We can send control value or any value from client side(Javascript) to server side (Code behind) by using AJAX page method concept:
Place script manager in a webpage and
Here we need to enable "EnablePageMethods" Property of ScripManager.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
</asp:ScriptManager>
Default.aspx:
==========
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchUser.aspx.cs" Inherits="Wizard.SearchUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function startSearch(val) {
PageMethods.SendValueToServerSide(val);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
</asp:ScriptManager>
<div>
<asp:TextBox ID="txtval" runat="server"></asp:TextBox>
<asp:Button ID="btnSearchInput" runat="server" Text="SendSearchInput" OnClientClick="
startSearch('
txtval.value'
)
" /> </div>
</form>
</body>
</html>
Default.aspx.cs:
===========
[System.Web.Services.WebMethod]
public static void SendValueToServerSide(string clientsidevalue)
{
string searchinputfromclientside = clientsidevalue;
}
No comments:
Post a Comment