简体   繁体   English

UpdatePanel不刷新

[英]UpdatePanel doesn't Refresh

I have got a simple page with a HtmlInputHidden field. 我有一个带有HtmlInputHidden字段的简单页面。 I use Javascript to update that value and, when posting back the page, I want to read the value of that HtmlInputHidden field. 我使用Javascript更新该值,并且在回发页面时,我想读取该HtmlInputHidden字段的值。 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). 该HtmlInputHidden字段的Value属性在回发时为默认值(创建页面时所具有的值,而不是通过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. 我还尝试向ScriptManager.RegisterHiddenField(Page,“ MyHtmlImputHiddenField”,“ initialvalue”)注册HtmlInputHidden字段,但是即使我(通过javascript)可以检查该值是否已更改,也仍然只能读取“ initialvalue”。

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. 我尝试对行ID进行硬编码,令我惊讶的是,回发后的gridview在删除之前完全相同,但是记录已从数据库中删除。 (I´ve called the databind method). (我称之为databind方法)。

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

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. 这些将是我的建议。

When I do a postback the value is the same what was postedback. 当我执行回发时,该值与回发时相同。 I think updatepanel wasnt refresh. 我认为updatepanel没有刷新。 I tried to do __doPostBack('UpdatePanel1',''), didnt work either. 我试图做__doPostBack('UpdatePanel1',''),也没有起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM