Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am using Ajax Toolkit on my content page . I have an Javascript Code which i want to call from the code behind using ScriptManager.RegisterStartupScript.

The javaScript Code is :-
JavaScript
<script type="text/javascript"> 
   function disp_confirm() { 
       var r = jConfirm("Your Shift End ! Do you still want to Continue ? ") 
       if (r == true) { 
           jAlert("You pressed OK!") 
       } 
       else { 
           jAlert("You pressed Cancel!") 
       } 

How to call this disp_confirm()method of javascript from the code behind using C# .
Posted
Comments
amitsharma.niitjp 23-Mar-14 3:27am    
Hello Sir,

I want to access javascript in my contents page in asp.net,here is my javascript code

<asp:Content ID="Content1" ContentPlaceHolderID="heading" runat="server">
<script type="text/javascript" language="javascript">
var returnamount, totreturnamount, totreturnamount1, totreturnamount2, num, num1, num2, num3;
var interest1;
var result1;
function copy_data(val) {
var a = document.getElementById(val.id).value
document.getElementById("TotInst").value = a;
// var a = document.getElementById("body_TimePeriod").value
// document.getElementById("body_TotInst").value = a;
}
function copy_data1(val)
{
// returnamount = 25;
// alert(returnamount);

returnamount = document.getElementById(val.id).value;
document.getElementById("TotRetAmt").value = returnamount;
alert(returnamount);
var b = (document.getElementById("LoanAmnt").value) / (document.getElementById("TotInst").value);

document.getElementById("AmtPerInst").value = b.toFixed(2);
num = b.toFixed(2) - Math.floor(b);
document.getElementById("inst1").value = Math.round(parseFloat(document.getElementById("AmtPerInst").value) + (num * document.getElementById("TotInst").value));
num1 = document.getElementById("inst1").value;
interest1 = document.getElementById("AmtPerInst").value;
document.getElementById("TotAmtPerInst").value = Math.floor(b);
}
function amntInst(val) {
var c = document.getElementById("body_LoanAmnt").value / document.getElementById("body_TotInst").value
document.getElementById("body_AmtPerInst").value = c
}
function TotInt(val) {
var result = interest1;
var d = parseFloat(result) + parseFloat(document.getElementById("body_IntPerInst").value);
document.getElementById("body_TotAmtPerInst").value = Math.floor(d);
result1 = document.getElementById("body_TotAmtPerInst").value;
var g = parseFloat(num1) + parseFloat(document.getElementById("body_IntPerInst").value);
document.getElementById("body_inst1").value = Math.floor(g);
num2 = document.getElementById("body_inst1").value;
num3 = num2 - result1;
totreturnamount1 = (parseFloat(num3) + (parseFloat(document.getElementById("body_TotAmtPerInst").value) * parseFloat(document.getElementById("body_TotInst").value)));
document.getElementById("body_TotRetAmt").value = totreturnamount1;

}
function SerChr(val) {
var f = parseFloat(result1) + parseFloat(document.getElementById("body_SerPerInst").value)
document.getElementById("body_TotAmtPerInst").value = Math.floor(f);
totreturnamount = (parseFloat(num3) + (parseFloat(document.getElementById("body_TotAmtPerInst").value) * parseFloat(document.getElementById("body_TotInst").value)));
document.getElementById("body_TotRetAmt").value = totreturnamount;
var h = parseFloat(num2) + parseFloat(document.getElementById("body_SerPerInst").value);
document.getElementById("body_inst1").value = Math.floor(h);
}
</script>


please help me coz its very urgent for me

Try this :

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "disp_confirm();", true);
 
Share this answer
 
Try this:
C#
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MyFun1", "disp_confirm();", true);



--Amit
 
Share this answer
 
v2
try this Code

XML
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>disp_confirm();</script>", false);



regards

sarva
 
Share this answer
 
Comments
Member 10513966 24-Aug-17 3:41am    
Thanks. It worked for me
If you are working with AJAX UpdatePanel, following code should work for you. In my case, I was using update panel and none of the about worked except this one.

C#
ScriptManager.RegisterStartupScript(myUpdatePanelID, myUpdatePanelID.GetType(), "myFunction", "myFunction();", true);


You can get more details from calling javascript function within ajax updatepanel[^]

Hope it helps you!
 
Share this answer
 
v2
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "disp_confirm();", 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