Using client side page load fire server-side event

Posted by Nadh123 under ASP.NET on 8/25/2012 | Points: 10 | Views : 1800 | Status : [Member] | Replies : 1
Using client side page load
fire server-side event

Mahendra
91-9908699686



Responses

Posted by: Ranjeet_8 on: 8/25/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
Design Page

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Testing Page</title>
<script type="text/javascript" language="javascript">
function TestingCodeBehind1() {
document.getElementById('<%= Label1.ClientID %>').innerHTML = '<%= TestingCodeBehind() %>';
return false;
}
function TestingCodeBehind2() {
document.getElementById('<%= Button2.ClientID %>').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<input id="Button1" type="button" value="Button One" onclick="javascript:TestingCodeBehind1()" /><br />
<asp:Button ID="Button2" runat="server" Text="" OnClick="ClickedME" /><br />
<input id="Button3" type="button" value="Button two" onclick="javascript:TestingCodeBehind2()" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>

C# Code

protected void Page_Load(object sender, EventArgs e)
{
Button2.Attributes.Add("style", "visibility :hidden");
}

protected string TestingCodeBehind()
{
return "this is a string from C# code behind " + DateTime.Now.ToString();
}
protected void ClickedME(object sender, EventArgs e)
{
Label1.Text = "You clicked this button on " + DateTime.Now.ToString();
}


Nadh123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response