我有一个Web表单,它接受用户输入,生成动态SQL查询并将结果输出到gridview。
SQL可能需要一段时间才能运行,因此我使用Bootstraps模式弹出窗口创建了一个加载屏幕。想法是在SQL运行时显示加载屏幕。
然而,加载弹出窗口显示 AFTER ,gridview已经填充了结果,这种方式会破坏加载屏幕的位置!!!
任何人都可以给我任何关于为什么会这样做的想法,并帮助我找到一个潜在的解决方案吗?
C#
return
的JavaScript
protected void btnRun_Click(object sender, EventArgs e)
{
//Display the loading popup
ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowLoading();", true);
//Declaring the SQL statement to be passed to the database
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlDataSource1.SelectCommand = "SQL Command Here";
gvResults.DataSource = SqlDataSource1;
gvResults.DataBind();
}
ASPX
function ShowLoading() {
$("#btnShowModalLoading").click();
}
模态
<button id="btnShowModalLoading" type="button" class="btn btn-info btn-lg hide" data-toggle="modal"
data-target="#modalLoading">
Open Modal</button>
答案 0 :(得分:1)
您在服务器端的OnClick处理程序中注册了ClientStartupScript。这意味着当处理程序完成并通过Postback或Ajax返回其数据时,脚本才会运行。
您需要附加客户端onclick事件,例如通过jQuery或通过按钮的onclientclick
属性,以及您将代码打开模式的位置。
答案 1 :(得分:0)
这是对请求的响应。为了实现这一点,你需要让你的运行按钮单击显示加载模式,然后在那里通过javascript提交。