Reputation: 1040
i am making a user control dynamically.
var controlMarkup = string.Empty;
Page page = new Page();
var customControl = page.LoadControl(control) as UserControl;
if (customControl != null)
{
var htmlForm = new HtmlForm();
var output = new StringWriter();
//output.Write("<div id = 'ControlName'>" + customControl + "</div>");
htmlForm.Controls.Add(customControl);
page.Controls.Add(htmlForm);
HttpContext.Current.Server.Execute(page, output, false);
controlMarkup = output.ToString();
}
return controlMarkup;
nut now i want to get the textbox id of user control in external javascript can anyone help me to get the id of control.
Upvotes: 2
Views: 839
Reputation: 1040
I have got the solution of this Problem i just use the javascriptserializer to get the client id's of the dynamic control its very good approach because RegisterCLientScript is a methos which write the string from JavaScript Serializer on the page then u can easily get ur desired ID,s of the dynamic Control
Upvotes: 0
Reputation: 7449
If you are using .net 4.0 add ClientIDMode="Static" to your control.
Something like:
yourControlname.Attributes.Add("ClientIDMode", "Static");
For previous version of .net, because you are using external javascript you have two options
Upvotes: 0
Reputation: 238086
The client-side ID can be found in the ClientID
property. For example, you can hide a control called txtDistance
using jQuery in the .aspx
page like:
$('#<%= lblDistance.ClientID %>').hide();
Upvotes: 1