Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I want to call a javascript method from cs page which I am calling at the time of onchange event of html select . when I bind controls in edit case I want to fill that dropdown from cs page by calling that javascript method .

thanks in advance
Posted
Updated 17-Apr-13 21:22pm
v2

try this ..

XML
<div id="divvvv" runat="server">
    <select id="ddlSelect" onchange="changeTest()" name="select1">
           <option value="0" selected="selected">Choose a color</option>
           <option value="1">Red Star</option>
           <option value="2">Yellow Star</option>
           <option value="3">Pink Star</option>
         </select>




in cs file call like this
  divvvv.Attributes.Add("onClick", "javascript:return BindSelect();");
 
Share this answer
 
this is how you can call javascipt method from cs page

XML
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("<script laungauge='javascript'>");
strBuilder.Append(" MethodName();");
//javascript function name
strBuilder.Append("</script>");

//register script

Page.ClientScript.RegisterStartupScript(GetType(), "InitDiag", strBuilder.ToString());


change the MethodName to yours javascript methods name
 
Share this answer
 
Comments
shoaib Naeem 18-Apr-13 2:48am    
hello

thanks for help. I tried above code but it's not call my javascript method.
vinayakJJ 18-Apr-13 3:32am    
is your javascript method inside aspx page or in separate .js file
for just testing write this code in your aspx page
function printing()
{
window.print();
}

and then change in my previously given codes method name to printing
like this

StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("<script laungauge='javascript'>");
strBuilder.Append("printing();");
//javascript function name
strBuilder.Append("</script>");

//register script

Page.ClientScript.RegisterStartupScript(GetType(), "InitDiag", strBuilder.ToString());


and check if it works or not
Hi,

try like below.
C#
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), 'yourKey', 'YourJSFunction();', true);

refer ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String, Boolean)[^]

hope it helps.
 
Share this answer
 
try this:-

add script manager in your aspx page.

ScriptManager.RegisterStartupScript(Me,[GetType](),"key name", "javascriptMethodName();",true);

ScriptManager.RegisterStartupScript(Me, [GetType](), "DatePicker", "DatePicker();", True)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900