473,586 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:ope nDoc();");
in the page_load / page_prerender etc...

any ideas appreciated.

--
adi
Jan 30 '06 #1
3 13602
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(objec t sender, System.EventArg s 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:ope nDoc();");
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(objec t sender, System.EventArg s 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:ope nDoc();");
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(objec t sender, System.EventArg s 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:ope nDoc();");
in the page_load / page_prerender etc...

any ideas appreciated.

--
adi

Jan 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5055
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT...
3
4026
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the...
2
2649
by: shree | last post by:
Hi all, I'm trying to call javascript function via onLoad but running into a problem. I would appreciate any help and suggestion. My application is as follows. When a page loads, I want to check whether the vistor has the site's cookie present in their browser. If its not present, then to redirect user to a login page (script). If the...
4
4276
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to...
3
1390
by: Chris B. | last post by:
I'm getting some strange results in an asp.net web application that has recently gone live. In the header of almost all the pages, the full name of the currently logged in user is displayed. On occasion, this changes to the name of some other user currently on the site. Needless to say, some find this disconcerting. The routines that...
2
2502
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm using callback technique so I can change those two proprties via ChangeNumber1 and ChangeNumber2 functions. what happens is that when I change the...
1
6452
by: saiyen | last post by:
Hey all, ive been banging my head agains the wall for a few days now, and finally decided to ask for help. i have a document that writes the header with all the javascript in it, then modifyes a <div> tag with a button. the button has an onClick event that is supposed to call a javascript function in the header. The whole application works...
6
10103
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
4
3851
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.