2

this problem has wasted much of my time. I have written a javascript function and assigned value to asp hidden field but when i run my application i am not getting the value in c# variable please correct me if i am missing something. thanks in advance. here is my code javascript function:

function sureDelete() {
            if (confirm("DELETE USER?") == true) {              
                document.getElementById("hidden_yesno").setAttribute("Value", "1");
              //document.getElementById('deleteYesNo').value = 1;
            } else {                         
                document.getElementById("hidden_yesno").setAttribute("Value", "0");
               //document.getElementById('deleteYesNo').value = 0;
            }
            return true;
        }

my hidden field and click event

<asp:HiddenField ID="hidden_yesno" runat="server" />
<asp:ImageButton  runat="server" CssClass="pt-userDeactive help" CommandName="deleteuser"
CommandArgument='<%# Eval("user_id") %>' ImageUrl ="../TemplateS/assets/images/delete.png"
Width="25px" Height="25px" OnClick="Unnamed_Click" OnClientClick="return sureDelete()"/>

and following is the c# code

 protected void Unnamed_Click(object sender, ImageClickEventArgs e) {
            string flag = hidden_yesno.Value.ToString();
              //here i am getting the value as: ""            
            if (flag == "1") {
               //do something
            } else {
                //do nothing
            }          
        }

1 Answer 1

5

You are using asp:HiddenFeild whose ID is changed by asp.net according to ContentPlaceHolder so it is not found by javascript/jquery.

Either you need exact ID of hidden feild or you can set ClientIDMode="static" which will make sure that ID is not changed.

<asp:HiddenField ID="hidden_yesno" runat="server" ClientIDMode="Static" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.