Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have created a javascript function for dragging an control from codebehind through the use of string builder.


but i dont know how can i call this function


please some one help me...


thanks in advance
Posted

if you have java script function on aspx page lets say "MyFunc()"

and if you want to call this function on specific button click then

write Add attribute to your button in code behind page as show in below

C#
btnSave.Attributes.Add("onclick","return MyFunc()");


if you want to call java script on dropdown value change then call as below

C#
ddlStatus.Attributes.Add("OnChange","MyFunc()");



if you want to call java script on page load call function below in page load

C#
ClientScript.RegisterStartupScript(GetType(), "key", "Test();", true);
 
Share this answer
 
Refer - Call javascript function from codebehind in asp.net[^].
Quote:
C#
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "MyJavascriptFunction();", true);
 
Share this answer
 
Comments
Kriti Sharma 10400841 4-Jul-14 6:33am    
but where i need to place this code???
Where you want to call the function inside Code behind event/function.

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