Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在单击事件期间刷新页面两次_C#_Asp.net_Sql_Sharepoint - Fatal编程技术网

C# 在单击事件期间刷新页面两次

C# 在单击事件期间刷新页面两次,c#,asp.net,sql,sharepoint,C#,Asp.net,Sql,Sharepoint,我正在开发一个以ASP.NET和C作为代码隐藏的网页。 我有一个带有按钮的页面,它应该触发一个事件来刷新或重新渲染页面2次并启动SQL查询:1是在SQL查询运行时使GUI处于非活动状态,2是刷新或重新渲染以切换回正常GUI 我已经用Response.Redirect尝试过了,所以页面会进行回发,在page_Load-Event中,我会检查isGUInactive变量。如果为true,GUI将被禁用,直到SQL查询完成,然后我再次刷新并将isGUIinactive设置为true,这样GUI将在Pa

我正在开发一个以ASP.NET和C作为代码隐藏的网页。 我有一个带有按钮的页面,它应该触发一个事件来刷新或重新渲染页面2次并启动SQL查询:1是在SQL查询运行时使GUI处于非活动状态,2是刷新或重新渲染以切换回正常GUI

我已经用Response.Redirect尝试过了,所以页面会进行回发,在page_Load-Event中,我会检查isGUInactive变量。如果为true,GUI将被禁用,直到SQL查询完成,然后我再次刷新并将isGUIinactive设置为true,这样GUI将在Page_Load-Event中的另一次回发中启用。 但是Response.Redirect不能这样工作。它等待按钮单击方法完成,然后执行回发。 你能为我提供一些替代方案,让我的页面刷新或重新阅读两次,以实现我的目标吗

private void button_Click(object sender,EventArgs e)
{  
   isGUIinactive = true; // Disable GUI
   Response.Redirect(Request.RawUrl, false); // Disable GUI in PostBack

   using (SqlConnection connection = new SqlConnection(connectionString))
      {
          connection.Open();

          SqlCommand command = new SqlCommand(sqlcomm, connection);
          command.CommandType = CommandType.Text;
          SqlDataReader reader = command.ExecuteReader();  
          DataTable dt = new DataTable();
          dt.Load(reader);
          BindData(dt); // Bind Data to GridView
      }
   isGUIinactive = false; // Enable GUI
   Response.Redirect(Request.RawUrl, false); // Enable GUI in PostBack
}
更新:

ASP:

好吧,下面是:

基本上,一个简单的解决方案是调用javascript函数禁用GUI,然后执行asp.net单击

它可以通过
onClientClick
属性轻松完成,它调用javascript函数,然后执行OnClick

我举了一个例子,它有一个page Default.aspx页面,在这个例子中,我隐藏了gui div,并在页面上放了一个blocking div:

html:


函数lockGUI(){
var blocking_div=“正在加载,请稍候。”;
var GUIPanel=document.getElementById(“UI_DIV”);
GUIPanel.style[“可见性”]=“隐藏”;
document.body.innerHTML+=blocking_div;
}
这是用户界面
c#:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
公共部分类\u默认值:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
对于(int i=0;i<100000000;i++)
{
//只是一个代码块,使其加载时间长,替换为您的。
}
重定向(“Default.aspx”);
}
}

如果您有任何问题,请随时提问。

首先,当您执行响应重定向时,其余代码将不会执行。如果您想禁用gui,请使用部分页面呈现。你可以通过控制面板来实现。你是在逃避javascript吗???你似乎想通过电脑上的c#来完成所有的工作server@Banana你说得对,更新了我的问题,忘记添加参数。@user3453011 stackunderflow是对的,你应该使用javascript来获得最佳结果。如果我有时间,我会给你写一些简洁的例子非常感谢,但是我的OnClick-Event似乎因为OnClientClick-Event而被忽略了是的,我的朋友,这正是为什么
使用submitbehavior=“false”
把它放进去,你的点击甚至会被执行谢谢,但是我已经包括了这个片段:脚本正确执行并锁定了整个GUI。你的OnClick被忽略了?你能在你的click处理程序中设置一个断点,看看那里的代码是否失败了吗?
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$"  %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint"  Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true"  CodeBehind="GUIUserControl.ascx.cs" Inherits="Project.GUI.GUIUserControl" %>

<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">


<script type="text/javascript">
  function lockGUI() {
      var blocking_div = "<div style='" +
            "position:fixed;" +
            "width:100%;" +
            "height:100%;" +
            "left:0;" +
            "top:0;" +
            "background-color:#444455;" +
            "color:white;" +
            "text-align:center;font-size:20px;" +
            "'>Loading</div>";
      var GUIPanel = document.getElementById("block_div");
      GUIPanel.style["visibility"] = "hidden";
      document.body.innerHTML += blocking_div;

  }

    </script>

<body>

<div id="block_div" style="background-color:White;">

// Big GridView

<asp:Table ID="Table1" runat="server" BorderWidth="0px" Width="233px" 
Height="16px">
<asp:TableRow ID="Tr1" runat="server" >
    <asp:TableCell>
        <asp:Button UseSubmitBehavior="false"  ID="btnsynchro" runat="server" Text="synchronize table" 
OnClick="btnsynchro_Click" OnClientClick="lockGUI();" />
    </asp:TableCell>

    <asp:TableCell>
        <asp:Button ID="btntest" runat="server" Text="for testing" 
        onclick="btntest_Click"/>
    </asp:TableCell>
</asp:TableRow>

  </asp:Table>

</div>

</body>
</html>
protected void btnsynchro_Click(object sender, EventArgs e)
 {
using (SqlConnection connection = new SqlConnection(connectionString))
  {
      connection.Open();

      SqlCommand command = new SqlCommand(sqlcomm, connection);
      command.CommandType = CommandType.Text;
      SqlDataReader reader = command.ExecuteReader();  
      DataTable dt = new DataTable();
      dt.Load(reader);
      BindData(dt); // Bind Data to GridView
  }
 Response.Redirect(Request.RawUrl, false);
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function lockGUI() {
            var blocking_div = "<div style='" +
                "position:fixed;" +
                "width:100%;" +
                "height:100%;" +
                "left:0;" +
                "top:0;"+
                "background-color:#444455;" +
                "color:white;" +
                "text-align:center;"+
                "'>Loading, Please wait.</div>";
            var GUIPanel = document.getElementById("UI_DIV");
            GUIPanel.style["visibility"] = "hidden";
            document.body.innerHTML += blocking_div;

        }

    </script>

</head>
<body>
    <form runat="server" id="TheForm">
   <div id="UI_DIV" style="background-color:red;">
       this is the ui 
       <asp:Button UseSubmitBehavior="false" OnClientClick="lockGUI();" ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
   </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 1000000000; i++)
        {
             //just a codeblock to make it load long, replace with yours.
        }
        Response.Redirect("Default.aspx");
    }
}