Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a problem I am unable to solve.

1) I am creating some dynamic controls in the OnInit() method of the page by calling the LoadControls() method.
2) Inside the LoadControls() method I am getting a list from a database of what type of controls to add to the page, and what thier values are.
3) I create either a RadioButtonList, CheckBoxList or DropDownList.
4) I have set AutoPostBack = true and attached the SelectedIndexChanged event handler and method.
5) The CheckBoxLists and RadioButtonLists retain their values after PostBack and fire the SelectedIndexChanged event, the DropDownList doesn't do either.
All 3 control types are being treated the same during creation, not sure what I'm missing?
PostBack is happening for the DropDownList, just no event is being fired.
Thanks,
my code is -

XML
<asp:DropDownList ID="ddlsmslist" runat="server" EnableViewState="true"
        Width="600px" AutoPostBack="True"
            onselectedindexchanged="ddlsmslist_SelectedIndexChanged"  >
    </asp:DropDownList>



C#
protected override void OnInit(EventArgs e)
    {

        //if (!IsPostBack)
        //{
        //if (ddlsmslist.SelectedIndex != 0)
        //{
        this.ddlsmslist.SelectedIndexChanged += new EventHandler(ddlsmslist_SelectedIndexChanged);

            cntrlCount = -1;
            base.OnInit(e);
            string[] temp = new string[10];
            indexing = new string[100];
            template = template.Replace("##Field##", "&");
            temp = template.Split('&');

            for (int i = 0; i < temp.Length; i++)
            {

                cntrlCount++;
                Label l = new Label();
                l.ID = "lbl" + cntrlCount;
                l.Style.Add("float", "left");
                l.Text = temp[i].ToString();
                templateFormPlaceholder.Controls.Add(l);
                indexing[cntrlCount] = "lbl";
                if (i < temp.Length - 1)
                {
                    cntrlCount++;
                    indexing[cntrlCount] = "txt";
                    TextBox t = new TextBox();
                    t.ID = "txtBox" + cntrlCount;

                    t.Style.Add("float", "left");
                    templateFormPlaceholder.Controls.Add(t);
                }

            }

            templateFormPlaceholder.Visible = true;
            submit.Visible = true;
            divcontant.Visible = true;
        //}

        //else
        //{
        //    templateFormPlaceholder.Visible = false;
        //    submit.Visible = false;
        //    divcontant.Visible = false;

        //}


}


C#
protected void ddlsmslist_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlsmslist.SelectedIndex != 0)
    {
        GetSmsTemplatebyid smstemplate = new GetSmsTemplatebyid();
        GEtSmsSettingsOutput smstemplateoutput = new GEtSmsSettingsOutput();
        InsertSmslogseInput smstemplateinput = new InsertSmslogseInput();
        smstemplateinput.Sms_Id = Convert.ToInt32(ddlsmslist.SelectedItem.Value);
        smstemplateoutput = smstemplate.Execute(smstemplateinput);
        template = smstemplateoutput.Sms_Template;

    }
    else
    {

    }


}

plz help me anyone.
Posted
Updated 13-Feb-14 20:30pm
v3
Comments
Jaydeep Jadav 14-Feb-14 1:55am
   
please format your question and use code block

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900