Solved

calling javascript onload of a user control

Posted on 2008-06-11
6
4,467 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
Independent Software Vendors: 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

713 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