views:

568

answers:

3

I have got a simple page with a HtmlInputHidden field. I use Javascript to update that value and, when posting back the page, I want to read the value of that HtmlInputHidden field. The Value property of that HtmlInputHidden field is on postback the default value (the value it had when the page was created, not the value reflected through the Javascript). I also tried to Register the HtmlInputHidden field with ScriptManager.RegisterHiddenField(Page, "MyHtmlImputHiddenField", "initialvalue") but it still only lets me read the 'initialvalue' even though I (through javascript) can inspect that the value has changed.

I tried to hardcoded the rowid and, to my surprise, after postback gridview was exactly the same before the delete but the record was deleted from the database. (I´ve called the databind method).

  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);
      }
   }
A: 

On a postback, when the page loads is the view of the hidden field what was posted back or is it the value you set when the page loads? It may be that you have to worry about the case where in the postback you aren't resetting a value to what it was originally. Another point is that if you do a delete, are you refreshing the data that you show or is it the same? Those would be my suggestions.

JB King
A: 

When I do a postback the value is the same what was postedback. I think updatepanel wasnt refresh. I tried to do __doPostBack('UpdatePanel1',''), didnt work either.

A: 

can you post your aspx source?

rams