UpdatePanel does not update

I have a simple page with an HtmlInputHidden field. I am using Javascript to update this value, and when posting back the page, I want to read the value of this HtmlInputHidden field. The Value property of this HtmlInputHidden field returns the default value (the value it had when the page was created, not the value rendered through Javascript). I also tried registering the HtmlInputHidden field with ScriptManager.RegisterHiddenField (page, "MyHtmlImputHiddenField", "initialvalue"), but it still allows me to read the "initial value" even though I (via javascript) can verify that the value has changed.

I tried to hard-code the rowid, and to my surprise, after the postback gridview was exactly the same before deleting, but the record was deleted from the database. (I named the method of data binding).

  protected void gridViewDelete(object sender, GridViewDeleteEventArgs e)
  {

      bool bDelete = false;
      bool bCheck = false;

      if (hfControl.Value != "1")
      {
          // check relationship
          bCheck = validation_method(.......);
          if (bCheck)
          {
              bDelete = true;
          }   
      }
      else
      {
          hfControl.Value = "";
          bDelete = true;
      }

      if (bDelete)
      {
          //process delete
      }
      else
      {
          string script = string.Empty;

          script += " var x; ";
          script += " x = confirm('are u sure?'); ";
          script += " if (x){ " ;
          script += " document.getElementById('hfControl').value  = '1'; ";
          script += " setTimeOut(__doPostBack('gridView','Delete$"
                                      + e.RowIndex + "'),0);";
          script += " } ";

          ScriptManager.RegisterClientScriptBlock(this,
                                       Page.GetType()
                                       , "confirm"
                                       , script
                                       ,true);
      }
   } 

      

+1


source to share


2 answers


In postback, when the page load is a kind of hidden field, what was sent back, or is it the value you set when the page loads? You may have to worry about where in the postback you are not returning the value to what it was originally. Another thing is that if you do a delete, are you updating the data you are showing, or is it the same? These will be my suggestions.



0


source


When I post back it is the same thing that was posted back. I guess the updatepanel was not updated. I tried to do __doPostBack ('UpdatePanel1', ''), also didn't work.



0


source







All Articles