How to call event using javascript?
-
My aspx page contains following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">function fnClickCalc() { document.getElementById('<%= btnCalc.ClientID %>').click(); } </script>
</head>
<body>
<form id="form1" runat="server"></form>
</body>
</html>My code behind file is,
protected void btnCalc_Click(object sender, EventArgs e)
{lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
}
When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)
Cheers,
SMPMy Recent Article
Main Method in C# -
My aspx page contains following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">function fnClickCalc() { document.getElementById('<%= btnCalc.ClientID %>').click(); } </script>
</head>
<body>
<form id="form1" runat="server"></form>
</body>
</html>My code behind file is,
protected void btnCalc_Click(object sender, EventArgs e)
{lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
}
When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)
Cheers,
SMPMy Recent Article
Main Method in C#Try:
OnClientClick="fnClickCalc();return false;"
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Try:
OnClientClick="fnClickCalc();return false;"
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks..It works..It was so simple. Really appreciate your answer :-D
Cheers,
SMPMy Recent Article
Main Method in C# -
My aspx page contains following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">function fnClickCalc() { document.getElementById('<%= btnCalc.ClientID %>').click(); } </script>
</head>
<body>
<form id="form1" runat="server"></form>
</body>
</html>My code behind file is,
protected void btnCalc_Click(object sender, EventArgs e)
{lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
}
When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)
Cheers,
SMPMy Recent Article
Main Method in C#Include jquery library from Jquery.com in header section. Change YOur Function to this ..
<script type="text/javascript" language="javascript">
function fnClickCalc() { var lbl1 = $("#lblFirstNo"); var lbl2 = $("#lblsecondNo"); var lbl3 = $("#lblResult"); lbl3.Text = lbl1.Text + lbl2.Text ; } </script>