get the javascript variable value to Code Behind Asp.net
- by Siddiq Baig
i am trying to pass the javascript variable value to hidden feild from code behind by onclientclick event.. i have button that have both client and server side onclick event
<asp:Button ID="btnSave" runat="server" Text="Save" class="buttonstyle"
onclick="btnSave_Click" OnClientClick="otherdata()" />
i want to get the javascript value in codebehind from OnClientClick event and then want to insert that value to database table from Onclick event
function otherdata() {
var hv = $('input[id$=hdnOthers]').val();
var $arrT = $('#<%=gv_Others.ClientID %>').find('input:text[id$="txtEmp"]');
var count = [];
for (var i = 0; i < 10; i++) {
var $txt = $arrT[i];
count[i] = $($txt).val();
}
hv = count;
alert(hv);
}
i am getting the value in alert and assigning the value to hidden field but problem is that i am not getting the value in hidden field from code behind.. although i have already pass the value to hidden field from javascript so why i am not getting that value from code behind..
protected void Insert_OtherServices()
{
dsJobCardTableAdapters.Select_OtherServiceTableAdapter dsother = new dsJobCardTableAdapters.Select_OtherServiceTableAdapter();
string hdn = hdnOthers.Value;
dsother.Insert_OtherService(hdn);
}