2012-02-17 208 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

相關問題