471,318 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

How to Call Javascript function from a User Contorl?

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.

--
adi
Jan 30 '06 #1
3 13433
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>");
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"anadimpa" wrote:
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.

--
adi

Jan 30 '06 #2
I tried your approach, but the whole text is rendering onto the page as text:

openDoc();
--
adi
"Peter Bromberg [C# MVP]" wrote:
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>");
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"anadimpa" wrote:
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.

--
adi

Jan 30 '06 #3
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
--
adi
"anadimpa" wrote:
I tried your approach, but the whole text is rendering onto the page as text:

openDoc();
--
adi
"Peter Bromberg [C# MVP]" wrote:
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>");
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"anadimpa" wrote:
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.

--
adi

Jan 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Chris B. | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.