避免页面刷新
我必须避免页面刷新。每次我单击提交按钮时,页面都会刷新。我该如何避免这种情况?
protected void Button1_Click(object sender, EventArgs e)
{
string firstname = DropDownList1.SelectedItem.Text;
if (firstname == "All")
{
da = new SqlDataAdapter(query, con);
}
dt = new DataTable();
dt = ds.DataTable1;
da.Fill(dt);
rdc.Load(Server.MapPath("CrystalReport.rpt"));
rdc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rdc;
CrystalReportViewer1.RefreshReport();
}
I have to avoid page refresh. Every time I click the submit button, page is refreshed. How do I avoid that?
protected void Button1_Click(object sender, EventArgs e)
{
string firstname = DropDownList1.SelectedItem.Text;
if (firstname == "All")
{
da = new SqlDataAdapter(query, con);
}
dt = new DataTable();
dt = ds.DataTable1;
da.Fill(dt);
rdc.Load(Server.MapPath("CrystalReport.rpt"));
rdc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rdc;
CrystalReportViewer1.RefreshReport();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将需要更新的所有内容放在
中。您可以在 Ajax Control Toolkit 中找到该控件,
您还必须添加一个
在页面顶部。I would suggest putting everything that needs to be updated in an
<asp:UpdatePanel>
.You can find that control in the Ajax Control Toolkit
You will also have to add a
<asp:ScriptManager>
on top of your page.如果您不想刷新整个页面,请使用 UpdatePanel 进行部分渲染或使用正确的 ajax 方法。
您现在使用服务器端按钮单击所做的方式是最慢的,并且会生成整页回发和刷新,除非您至少使用 UpdatePanel。
请在此处查看有关如何将 Crystal Report 查看器与 Ajax 结合使用的讨论:将 AJAX 与 Crystal Report 结合使用查看器
if you do not want a full page refresh either use UpdatePanel for partial rendering or proper ajax approach.
the way you are doing now with a server side button click is the slowest and generates a full page postback and refresh unless you use an UpdatePanel at minimum.
check here for a discussion on how to use the Crystal Report viewer with Ajax: using AJAX with crystal report viewer