2012年3月28日水曜日

Resolving <%=MyControl.ClientID%> in a clientside Script which is loaded via ScriptM

Hi experts and developers!

I have a problem using the <%=MyControl.ClientID%> syntax to resolve controls when using clientside script. I really need this functionality though because the control of which i need the clientside id is generated (and dynamically named) by a third party control (DataGrid) I use.

How is it possible to find out the ClientID of a control when the clientside script is loaded via ScriptManager.RegisterClientScriptInclude()?

Thanks for your help in advance!

Greetings,
Wolfgang

hello.

i think i'm not understanding your question very well. MyControl.ClientID gives you the ID of the client...maybe you just need to concatenate it to the rest of the string that is being register as script so that it works...can you show us the code where you're having the problem?


Hi Luis!

Your solution sound absolutely reasonable, but as i use a separate JavaScript File, the <%= %> syntax won't work. And also it does not sound to practicable to change the JavaScript file at runtime (all the time, because the ClientID of the controls changes).

I found a solution already though: I'm just using ClientScript.RegisterArrayDeclaration(MyClientID, myControl.ClientID) on Page_PreRender()... After that I can access the ClientID in my JavaScritp File just via MyClientID[0] as it is a normal js array.

Thanks for the reply!
Wolfgang


hi.

i'd do something like that too if i had the script in a separate file (which is really the recommended approach for script files:))

0 件のコメント:

コメントを投稿