开发者

!IsPostBack problem when Dynamically adding the checkbox control

开发者 https://www.devze.com 2023-03-13 02:07 出处:网络
I have a ascx page in which i am adding checkbox dynamically on dltest_ItemDataBound, I am binding the data, repopulating the check box every thing i am doing which is done very well, Now i am calling

I have a ascx page in which i am adding checkbox dynamically on dltest_ItemDataBound, I am binding the data, repopulating the check box every thing i am doing which is done very well, Now i am calling this ascx file on one aspx page say case.aspx, it that i have written the following code

private void GetModalities() {
    List<ListItem> lstRadiograph = new List<ListItem>();
    DataSet ds2 = objGetBaseCase.GetSubspecialities();
    ListItem list;
    MultipleModalitySelect1.DataSource = listItem;
    Pathophysiology.DataSource = objGetBaseCase.Pathophysiology();

    list = new ListItem();
    list.T开发者_开发技巧ext = "No add'l categories";
    list.Value = 0.ToString();
    SublistItem.Add(list);
    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++) {
        list = new ListItem();
        list.Text = ds2.Tables[0].Rows[i][1].ToString();
        list.Value = ds2.Tables[0].Rows[i][0].ToString();

        SublistItem.Add(list);
    }
    Subspecialities.DataSource = SublistItem;            
}

protected void Page_Load(object sender, EventArgs e) {        
    if (!IsPostBack) {
        GetModalities();                
    }
}

in this case.aspx page i have a text box

<asp:TextBox ID="txtAge" runat="server" 
       class="inputgb" Width="30px" MaxLength="3"></asp:TextBox>
<asp:Label ID="lblAgeErr" runat="server" 
  ForeColor="Red" Font-Bold="True" Font-Size="X-Large"
       Visible="False">*</asp:Label>

i am validating the text box by condition

if (txtAge.Text == "") {
    lblAgeErr.Visible = true;
    error = true;
} else {
    lblAgeErr.Visible = false;
}

THE PROBLEM IS

if am txtAge is empty then condition is causing, but Modality is populating empty on !IsPostBack and showing empty check boxs, and if i am calling GetModality(); out of !IsPostBack then condition is causing well checkbox is not populating but when i am selecting some value then it is not getting selected.

i am unable to find out what to do. so when txtAge is empty then checkbox should not populate empty when i write the GetModality() in inside the !IsPostBack when i should click on btn Next

0

精彩评论

暂无评论...
验证码 换一张
取 消