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 -
<asp:DropDownList ID="ddlsmslist" runat="server" EnableViewState="true"
Width="600px" AutoPostBack="True"
onselectedindexchanged="ddlsmslist_SelectedIndexChanged" >
</asp:DropDownList>
protected override void OnInit(EventArgs e)
{
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;
}
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.