asp.net - Best way of handling javascript within Custom Controls? -


I have some custom controls in ASP.Net that I have made. I used jQuery where it also helped. Well, a problem that I have (with a clear but "bad" workaround) is that for every user control, I executed some code from within pageLoad ( $ (document) / Code> will not work with the updated panel).

Well now my problem is that I have to attach two custom controls to pageLoad event

What would be the best way to do this?

I just can not do

  old_pageLoad = pageLoad pageLoad = function () {. .. old_pageLoad ();}  

Because these custom controls can be used more than once on the page and the script needs to be run for each instance of control, plus what If there are 3 different custom controls on the page?

The only way with which I came, it is something that looks like a super hack:

  old_pageLoad_ <% = MyStaticClass.GetUniqueID ()% & Gt; = Pageload; PageLoad = function () {... old_pageLoad_ & lt;% = MyStaticClass.GetUniqueID ()% & gt; ();}  

Are there any better ways to sort out these kinds of functions?

I have also seen this, but whatever suggestions I give, I feel bad about what I am currently doing.

ScriptManager . When you enter the script, you pass in the context of your control, and ensures that whenever the control is updated (the first page load, or when the update panel is updated) the initial script goes.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -