Solved

calling javascript onload of a user control

Posted on 2008-06-11
6
4,413 Views
Last Modified: 2010-08-17
I have a javascript function defined in my user control.  How do I call it in the OnLoad event of the User Control?
0
Comment
Question by:trebems
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:ajitha75
ID: 21759325
window.attachEvent('onload','javascriptfunction').

Write this in the start of the user control or inject it from server side
0
 

Author Comment

by:trebems
ID: 21759402
Sorry, but I'm pretty new to .net - when you say to write this in the start of the user control - where exactly would I put it - can you give me a small code snippet?
0
 
LVL 14

Expert Comment

by:ajitha75
ID: 21759666
This is how a sample usercontrol will look like. here instead of alert place your javascript function name

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Control2.ascx.cs" Inherits="Control2" %>
<script language="javascript" type="text/javascript">
window.attachEvent("onload", alert('test'));
</script>
<asp:TextBox ID="textBox2" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:trebems
ID: 21760844
Ok - that worked just fine - but then I relaized I have a different issue.  The user control is within an UpdatePanel, so, although the javascript function is called when the usr control first loads - I need it to be called everytime the Update Panel does a postback...  any thoughts on this?
0
 
LVL 14

Accepted Solution

by:
ajitha75 earned 50 total points
ID: 21761288
use RegisterStartupScript of ScriptManager
0
 

Author Comment

by:trebems
ID: 21772764
Thank  you for your response!  I haven't yet been able to try this as I'm in the home office and I've been tied up in meetings most of the time - but hope to get back to this issue early next week.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now