2012-02-17 112 views
0

我必须避免页面刷新。每次点击提交按钮,页面都会刷新。我如何避免这种情况?避免页面刷新

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

回答

1

我建议把需要在<asp:UpdatePanel>要更新的一切。 您可以在Ajax Control Toolkit中找到该控件

您还需要在页面顶部添加<asp:ScriptManager>

0

如果您不想整页刷新,请使用UpdatePanel进行局部渲染或使用适当的ajax方法。

您现在正在使用服务器端按钮的方式是最慢的,并且会生成完整页面回发和刷新,除非您至少使用UpdatePanel。

请点击这里查看关于如何结合Ajax使用Crystal Report查看器的讨论:using AJAX with crystal report viewer