2

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.

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

What do you mean by 'external'? You can't use this in .js files!
1

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();

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.