So I have a Web Forms asp control:
<asp:DropDownList runat="server" ID="ExistingTemplate" ClientIDMode="Static" />
On the backend code, it gets populated through this:
public override void DataBind()
{
base.DataBind();
var selectList = Chatham.Web.Models.Indications.DropDownData.AllEditableTemplates();
ExistingTemplate.DataSource = selectList.Items;
ExistingTemplate.DataTextField = selectList.DataTextField;
ExistingTemplate.DataValueField = selectList.DataValueField;
ExistingTemplate.DataBind();
SetTabVisibility();
}
Now, I want to refactor the AllEditableTemplates method to take a parameter. This parameter is only accessible through the client side Javascript code, on the master page front end.
How can I pass a parameter to this method that I get from Javascript on the page?
Expose it as a web method and have javascript call it, instead of it trying to get the value from javascript.
http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
Using a hidden field has a problem – normally, data bind is called right away somewhere, which means the initial request to the web server didn’t have the form field set yet and it will be empty. You would need a second request in order for it to populate so that your form request had it. Calling the web method from the client instead solves this problem.