Haseeb Khan
Haseeb Khan

Reputation: 1040

textbox id of user control in external java script

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

Answers (4)

Haseeb Khan
Haseeb Khan

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

Maysam
Maysam

Reputation: 7367

Try this $get("<%=lblDistance.ClientID%>")

Upvotes: 2

Emmanuel N
Emmanuel N

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

  1. Use hidden input to store clientId's
  2. View HTML produced by your page and use those Id's in your external javascripts

Upvotes: 0

Andomar
Andomar

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

Related Questions