2013-06-13 44 views
2

我想部分回發(asyncpostback),而不是fullpostback.but它不工作。動態創建的複選框,在那裏檢查或者未選中的複選框原因fullpostback 但它應該是asyncpostback.Here是我的代碼.....updatepanel觸發器導致fullpostback而不是部分回發

<asp:CheckBoxList ID="chkList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="chkList_SelectedIndexChanged" 
       ClientIDMode="AutoID"> 
      </asp:CheckBoxList> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
       <ContentTemplate> 

        <asp:Label ID="lblMessage" runat="server" Visible="false"></asp:Label> 
       </ContentTemplate> 
       <Triggers> 
        <asp:AsyncPostBackTrigger ControlID="chkList" EventName="SelectedIndexChanged" /> 
       </Triggers> 
      </asp:UpdatePanel> 

C#代碼:

private static readonly string constring = ConfigurationManager.ConnectionStrings["ConnectionStrRead"].ToString(); 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      SqlConnection con = new SqlConnection(constring); 
      SqlCommand com = new SqlCommand("Select * from Category"); 
      com.Connection = con; 
      con.Open(); 
      SqlDataAdapter da = new SqlDataAdapter(com); 
      DataTable dt = new DataTable(); 
      da.Fill(dt); 

      int dtRows = dt.Rows.Count; 
      List<string> itemList = new List<string>(); 
      for (int i = 0; i < dtRows; i++) 
      { 
       //itemList = new List<string>(); 
       string item = dt.Rows[i]["CategoryName"].ToString() + "(" + dt.Rows[i]["CreateUser"].ToString() + ")"; 
       itemList.Add(item); 
      } 
      chkList.DataSource = itemList.ToArray(); 
      chkList.DataBind(); 
      con.Close(); 
     } 
    } 

protected void chkList_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     lblMessage.Visible = true; 
     lblMessage.Text = string.Empty; 
     foreach (ListItem item in chkList.Items) 
     { 
      if (item.Selected) 
      { 
       lblMessage.Text += item.Text + "<br/>"; 
      } 
     } 
    } 

回答

2

ü可以檢查您的ScriptManager的EnablePartialRendering屬性。它必須是的EnablePartialRendering =「真」

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableViewState="False" EnablePartialRendering="true" EnableScriptGlobalization="true" > </asp:ScriptManager> 

如果問題不是關於u可以在代碼中嘗試添加AsyncPostBackTrigger背後

ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(chkList); 
+0

是否頁面加載事件火災如果控制是一個更新面板內?這裏選中或取消選中checkboxlist控件。 – ababil

+0

你救了我一天! – adripanico

相關問題