get the javascript variable value to Code Behind Asp.net
Posted
by
Siddiq Baig
on Stack Overflow
See other posts from Stack Overflow
or by Siddiq Baig
Published on 2014-05-31T08:56:30Z
Indexed on
2014/05/31
9:26 UTC
Read the original article
Hit count: 215
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);
}
© Stack Overflow or respective owner