Can i add a Javscript Onload from a UserCreated Control?

R

RSH

I have a situation where I am successfully adding an Onload to the Body tag
from the codebehind from a page using the following code:

Protected WithEvents body1 As System.Web.UI.HtmlControls.HtmlGenericControl



If Not IsPostBack Then

body1.Attributes.Add("OnLoad",
"preloadImages();javascript:document.all.UserLogin_txtUserName.focus()")

Else

body1.Attributes.Remove("OnLoad")

body1.Attributes.Add("OnLoad", "preloadImages();")

End If



Now I am creating a user control that needs to be able to do the same thing.
I added the code to the control but I get a null exception error when I add
the control to the page. Is there a way to do this?



Thanks!

Ron
 
S

Scott M.

you are adding the attribute to the control in the CONTROL'S Page_Load, not
the actual Page's Page_Load, right?
 
S

Scott M.

Just out of curiosity, if you comment the line of code in the contro's
Page_Load that sets the attribute, can you then successfully add it to your
form?
 
G

Guest

use the Page property of the control and the ClientScript
(RegisterClientScriptBlock, etc). to add window.onload.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top