UpdatePanel 不刷新

发布于 2024-07-09 16:03:15 字数 1615 浏览 6 评论 0原文

我有一个带有 HtmlInputHidden 字段的简单页面。 我使用 Javascript 来更新该值,并且在回发页面时,我想读取该 HtmlInputHidden 字段的值。 该 HtmlInputHidden 字段的 Value 属性在回发时为默认值(创建页面时的值,而不是通过 Javascript 反映的值)。 我还尝试使用 ScriptManager.RegisterHiddenField(Page, "MyHtmlImputHiddenField", "initialvalue") 注册 HtmlInputHidden 字段,但它仍然只允许我读取“初始值”,即使我(通过 javascript)可以检查该值已更改。

我尝试对 rowid 进行硬编码,令我惊讶的是,回发后 gridview 与删除之前完全相同,但记录已从数据库中删除。 (我称之为数据绑定方法)。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘香 2024-07-16 16:03:15

在回发时,页面加载时是回发的隐藏字段的视图,还是您在页面加载时设置的值? 您可能需要担心在回发中您没有将值重置为原始值的情况。 另一点是,如果您进行删除,您是否会刷新显示的数据还是相同的数据? 这些就是我的建议。

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.

执妄 2024-07-16 16:03:15

当我进行回发时,该值与回发的值相同。 我认为 updatepanel 没有刷新。 我尝试执行 __doPostBack('UpdatePanel1',''),也没有成功。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文