Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 17-Apr-13 21:23pm
Edited 17-Apr-13 22:22pm
_Amy51.5K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

try this ..
 
<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();");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

this is how you can call javascipt method from cs page
 
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
  Permalink  
Comments
Member 9697074 at 18-Apr-13 2:48am
   
hello
 
thanks for help. I tried above code but it's not call my javascript method.
hiphopper0123 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
try like below.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), 'yourKey', 'YourJSFunction();', true);
refer ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String, Boolean)[^]
 
hope it helps.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

try this:-
 
add script manager in your aspx page.
 
ScriptManager.RegisterStartupScript(Me,[GetType](),"key name", "javascriptMethodName();",true);
 
ScriptManager.RegisterStartupScript(Me, [GetType](), "DatePicker", "DatePicker();", True)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100