.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to register java script in asp.net 2008

Posted By: Ramesh     Posted Date: June 15, 2010    Points:2   Category :ASP.Net
Hi,

how to register javascript function in code behind of asp.net2008?

I am using C# as my code language

Regards,
Ramesh


Responses
Author: Lincy Lucy             
Posted Date: June 16, 2010     Points: 5   

See the following example

System.Text.StringBuilder sbScript = new System.Text.StringBuilder("");

sbScript.Append("<script language='javascript'>");
sbScript.Append("var w=0, h=0;");
sbScript.Append("if(document.all || document.layers)");
sbScript.Append("{");
sbScript.Append("w=screen.availWidth;");
sbScript.Append("h=screen.availHeight;");
sbScript.Append("}");
sbScript.Append("var popW = 900,");
sbScript.Append("popH = 500;");
sbScript.Append("var leftc = ( w - popW) / 2,");
sbScript.Append("topc = (h - popH) / 2;");
sbScript.Append("window.open('");
sbScript.Append("http://www.google.com");
sbScript.Append("', 'w_Locate',");
sbScript.Append("'left='+leftc+',top='+topc+',width=900, height=500, menubar=yes, resizable=no');");
sbScript.Append("w_Locate.focus();<");
sbScript.Append("/script>");

ScriptManager.RegisterStartupScript(this, this.GetType(), "@@@@MyPopUpScript", sbScript.ToString(), false);System.Text.StringBuilder sbScript = new System.Text.StringBuilder("");

sbScript.Append("<script language='javascript'>");
sbScript.Append("var w=0, h=0;");
sbScript.Append("if(document.all || document.layers)");
sbScript.Append("{");
sbScript.Append("w=screen.availWidth;");
sbScript.Append("h=screen.availHeight;");
sbScript.Append("}");
sbScript.Append("var popW = 900,");
sbScript.Append("popH = 500;");
sbScript.Append("var leftc = ( w - popW) / 2,");
sbScript.Append("topc = (h - popH) / 2;");
sbScript.Append("window.open('");
sbScript.Append("http://www.google.com");
sbScript.Append("', 'w_Locate',");
sbScript.Append("'left='+leftc+',top='+topc+',width=900, height=500, menubar=yes, resizable=no');");
sbScript.Append("w_Locate.focus();<");
sbScript.Append("/script>");

ScriptManager.RegisterStartupScript(this, this.GetType(), "@@@@MyPopUpScript", sbScript.ToString(), false);


You can do in a simillar manner.

With regards
Lincy Lucy
Exclusive offers & Discount on each order.Come and visit the beauty of God's Own Country
Author: JH             
Posted Date: June 18, 2010     Points: 5   

Hi,

You can resgister the javascript in codebehind..

But you want to ensure whether you are having ajax in your page or not..

If you have ajax in your page, you should be follow above sample code manner Or doesn't have any ajax in your page, you can use Page.ClientScript.RegisterStartupScript(),RegisterClientScriptBlock() and so on.

You can find so many example in online.

Thank..

Haribala

Author: Kirtan             
Posted Date: June 21, 2010     Points: 5   

Page.RegisterClientScriptBlock() method you can use to register it



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend