Setting HiddenField via jQuery not working in code behind
-
So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;
<a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>
Javascript;
function LoadDialog(accountId) {
$('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);$('#dialog').dialog('open'); return false; }
Dialog;
<div id="dialog" title="Delete Account">
Are you sure you wish to delete this account?<br /><br />
<asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
<asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
<a href="#" onclick="UnloadDialog()">No</a>
</div>When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.
Regards, Gareth. (FKA gareth111)
-
So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;
<a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>
Javascript;
function LoadDialog(accountId) {
$('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);$('#dialog').dialog('open'); return false; }
Dialog;
<div id="dialog" title="Delete Account">
Are you sure you wish to delete this account?<br /><br />
<asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
<asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
<a href="#" onclick="UnloadDialog()">No</a>
</div>When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.
Regards, Gareth. (FKA gareth111)
-
So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;
<a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>
Javascript;
function LoadDialog(accountId) {
$('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);$('#dialog').dialog('open'); return false; }
Dialog;
<div id="dialog" title="Delete Account">
Are you sure you wish to delete this account?<br /><br />
<asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
<asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
<a href="#" onclick="UnloadDialog()">No</a>
</div>When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.
Regards, Gareth. (FKA gareth111)
Problem solved. The HiddenField was always returning empty, even if i set it in the code behind. It was because it was located in a panel. Weird, not sure why, but once i moved it from one part of the page to the top (outside of the panel), it worked.
Regards, Gareth. (FKA gareth111)