Setting property value in UserControl using JavaScript or Ajax

Guess I got this code behind,

namespace nn.ss.tt
{
    public partial class abc: UserControl
    {
        private string _MyProperty;
        public string MyProperty
        {
            get { return _MyProperty; }
            set { _MyProperty = value; }
        } 
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
}

Now how can I set it's value here,

    <script type="text/javascript"> 
   $(document).ready(function () {
       var prm = Sys.WebForms.PageRequestManager.getInstance();    
       prm.add_initializeRequest(InitializeRequest);
       prm.add_endRequest(EndRequest);

    });        

    function InitializeRequest(sender, args) {
    }

    function EndRequest(sender, args) 
    {
       var hidField= $("[id$=_hidField]").val();

       // HERE I WANT TO set value of MY PROPERTY
    }

How can I do it sir ?

Answers


You cannot directly modify server controls' properties from the client side. I would try adding aspnet hidden field to the page and modify its value from the client side. Then during a postback/callback after ProcessPostData lifecycle event the assigned value will be in Value property of your input field and you can set MyProperty from it.


Need Your Help

Is it possible to pass a model to a layout in Express?

node.js mongodb express mongoose

I know that it is possible to pass a model to a view in express by doing something like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.