Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Thursday, April 23, 2015

How to Calling a Javascript function from c# code

Calling a Javascript function from c# code:



Hello friend one day I was trying to call a javascript function which will open the aspx child page from c# code behind. I tried using a literal control and assigned its text property the script funciton call.

litAlert.Text = "<script>callKeywords('" + Name + "','Keyword',+'Region');</script>";
 Where little Alert is the literal control. It works fine with a normal alert,

 but not sure what is the problem with this?

The JavaScript function is as given below:


Function call_Keywords(textid, Keywords, KeywordValue)
{

var url="Keywords.aspx?textvalue="+ textid +"&KeywordList="+Keywords+"&KeywordName="+KeywordValue;
var Parameters="location=0,toolbar=0,width=375,height=250,position=aboslute,
scrollbars=0,resizable=0";window.open(url,"School",parameters);

}

Some time we use fallowing option to call C# code by java script by this

ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript","callKeywords('" + Name + "','Keyword',+'Region');", true);

If you want to call java script code on C# code:

If you don't have the scriptManager you can use this:
Page.RegisterStartupScript("starScript", "callKeywords('" + Name + "','Keyword',+'Region');");



Asp.net Related Other Post:

No comments:

Post a Comment