#1  
Old 05-11-2008, 07:38 AM
9PM 9PM is offline
Junior Member
 
Join Date: May 2008
Posts: 4
Default Call Javascript from C# aspx.cs page


hi all,

How can I call Javascript function from aspx.cs code behind file? Can I directly call Javascript function from my C# code behind.

Thanks in advance
Reply With Quote
  #2  
Old 05-11-2008, 07:42 AM
Jane Jane is offline
Junior Member
 
Join Date: Feb 2008
Posts: 38
Default

Hi 9PM,

Set the Body tag in your page/master page to runat="server" and an id="TheBody".
Write the script tag in your page:
<script src="MyFunction.js" type="text/javascript"></script>

Then in the code behind attach the onload attribute to the body tag.

protected void Page_Load(object sender, EventArgs e)
{
MasterPageBodyTag = (HtmlGenericControl)Page.Master.FindControl("TheBo dy");
MasterPageBodyTag.Attributes.Add("Onload", "MyFunction()");
}

Best regards,
Jane
__________________
"Everything should be as simple as it is, but not simpler."
Albert Einstein

Last edited by Jane; 06-11-2008 at 02:15 PM.
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to increase my Google page rank? captain Advertising 2 09-07-2009 04:40 AM
How to make page redirection in ASP.NET? June ASP.NET Programming 1 08-21-2008 03:46 PM
Different Start Page in ASP.NET Sage ASP.NET Web Hosting 1 06-03-2008 11:24 AM
How to redirect a user to a certain web page? Peer ASP.NET Programming 1 04-15-2008 02:33 PM
Refresh a web page? Loopy ASP.NET Programming 1 03-11-2008 12:36 PM


All times are GMT. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Powerful Windows Dedicated Hosting & VPS ASP.NET Hosting