Using client side page load fire server-side event

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



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

Try this,
Design Page

<html xmlns="">
<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();
<form id="form1" runat="server">
<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>

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