?
Solved

calling javascript onload of a user control

Posted on 2008-06-11
6
Medium Priority
?
4,638 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

719 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