Jump to content
Xtreme .Net Talk

initialize a variable on first instance of a custom control


Recommended Posts

Posted

lets say i have several instances of the same custom control and i wanted the first one to load something and ignore that procedure with the rest of the custom control since its already loaded, anyone for directions?

 

was thinking of putting this in my custom control

 

<script language="javascript" src="something"></script>

 

but i wanted it to load only once even if i keep dragging more of the same custom control, anyone?

 

i can do a workaround like saving something in a session/viewstate, then check it from there, but there could be another way

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted

found an article for the solution, it was to emit it once for all server controls, however i keep on getting this "obsolete" warning at "Page.RegisterClientScriptBlock" line, im using VS 2005 Express

 

Const displayScriptKey As String = "someScript" 
If Not Page.IsClientScriptBlockRegistered(displayScriptKey) Then 
  Page.RegisterClientScriptBlock(displayScriptKey, script) 
End If 

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted

*** resolved

 

Const displayScriptKey As String = "someScript" 
If Not Page.ClientScript.IsClientScriptBlockRegistered(displayScriptKey) Then 
  Page.ClientScript.RegisterClientScriptBlock(Me.GetType, displayScriptKey, script) 
End If  

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...