Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 29, 2006 11:53 PM by Moskie
Apr 27, 2006 03:17 PM|LINK
Apr 29, 2006 10:20 AM|LINK
What do you mean with including whole script at once? If you have a script you can throw it out with
If you have it as external file then using RegisterClientScriptInclude (or RegisterClientScriptResource if its available as a web resource)
About the resource way:
Apr 29, 2006 11:17 AM|LINK
Apr 29, 2006 11:23 AM|LINK
you can always get the ASP.NET generated clientid by taking it from control's ClientID property. Does that help?
Apr 29, 2006 11:24 AM|LINK
Apr 29, 2006 11:25 AM|LINK
Apr 29, 2006 11:33 AM|LINK
Apr 29, 2006 11:44 AM|LINK
That is the "official" way getting the ID.
Why cannot you create only those function calls(s) which just take the ID in. That way, you wouldn't need to output all but only but those function calls from the control.
E.g put static part of the script into separate js file (or resource as was in the link I gave), and only make the calls into those functions which require the ID (generally speaking set the ID).
If you expect your control to exist only once on Page, you certainly could output just a js variable where the client ID would be given (script library would use that then)
May 05, 2006 07:15 PM|LINK
May 06, 2006 06:56 AM|LINK
Like said earlier, there's no hardcoding, if one takes ClientID of server-side control and uses that to create the ID into generated script.
Taking previous example say you have TextBox on form
<asp:TextBox ID="TextBox1" runat="server" />
You could make a script as follows
document.getElementById('<%=TextBox1.ClientID%>').value = "bar";
which would render the correct ID at client-side (client ID would change based on if control is placed inside a naming container such as a user control). Therefore creating js call is possible also in server-side code (this example was just inline script)
as TextBox is programmatically 100% available there (especially ClientID in this scenario)