Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

calling javascript onload of a user control

Posted on 2008-06-11
6
Medium Priority
?
4,679 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

885 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