Solved

calling javascript onload of a user control

Posted on 2008-06-11
6
4,381 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
listing all functions in JavaScript 19 114
Create XML 5 34
Handle null when using linq in this line 1 20
Jquery autocomplete 10 31
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now