How to Call Javascript function from a User Contorl?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all
I build a javascript function string in the code behind and register it in
the Page_Load of my User Control. I do this because I build the javascript
based on some variables that are passed to this user control.

How do I (or from where do I) call this function?
I tried several ways like:
this.Attributes.Add("onLoad", "javascript:openDoc();");
in the page_load / page_prerender etc...

any ideas appreciated.
 
In the case of a UserControl, I doubt onload would work. You could try just
writing it out inline in the Page_Load handler of the control:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("<script defer>doLoad();</script>");
}
 
Here's the whole story: I have a user control on my page, I want to change
its appearnace by calling a javascript function to do that (the control
responds to javascript calls).
I can now successfully call the function from within the page_render (thanks
peter) (which I build in the code behind), but I noticed that as soon as I go
to the page the javascript is called but it immidiately goes to the default
view.

I belive the call is being made from the pre_render, but once it is rendered
the control goes back to its original state - so i guess its now the question
of calling it from the right spot. any ideas gurus?

thanks
 

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

Back
Top