Hello ,
I read artical listed on link
http://www.tgreer.com/aspnet_html_04.html
What I am doing is.
on aspx page
1)There are two dropdown list on my .aspx page
2) One ddl ( drop down list) is populated on change of another one
3) One place holder to accomodate dynamic controls
On change of runtime populated ddl i am setting one session value to load which dynamic set of controls. This set of controls i read from XML and match with XSLT and display it.
dynamic set of user control's load mechenism reside in ascx ( User control) file.
There is one button i am adding runtime on the page load of ascx ( User control)
Every thing work fine first time and i get all the post back values on button click as well. when i change option in ddl . It load dynamic set of diffrenet controls fine as well.but button click lost. Intresting to know is if i click second time on button it works fine.
Code:
Code on .aspx page
==============
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if ( ViewState["mediaType"] != null)
{
if( ViewState["mediaType"].ToString() != "")
{
plControls.Controls.Clear();
plControls.Controls.Add(LoadControl("ucMediaXMLPar se.ascx"));
}
}
}
// On this index change i am loading another set of controls using XML
#region "Media Type Index Change"
private void cmbmedia_SelectedIndexChanged(object sender, EventArgs e)
{
if(cmbmedia.SelectedValue != null && cmbmedia.SelectedValue !="")
{
Session.Add ("mediaType",cmbmedia.SelectedValue.ToString()) ;
ViewState["mediaType"] = int.Parse(cmbmedia.SelectedValue);
plControls.Controls.Clear();
plControls.Controls.Add(LoadControl("ucMediaXMLPar se.ascx"));
plControls.Visible = true;
}
}
#endregion
On ascx ( user control)
===================
comments:
CreateControlsUsingXSLT method will match template with xml file and make controls
====================
#region "Page Load"
private void Page_Load(object sender, System.EventArgs e)
{
if ( Session["mediaType"] != null)
{
if( Session["mediaType"].ToString() != "")
{
Controls.Clear();
CreateControlsUsingXSLT(int.Parse(Session
["mediaType"].ToString()));
// this button click event has been lost
Button submitButton = new Button();
submitButton.Text= "Submit Me";
submitButton.ID= "btnSubmit";
submitButton.Click +=new EventHandler
(submitButton_Click);
Controls.Add(submitButton);
}
}
}
#endregion
private void CreateControlsUsingXSLT(int mediatype)
{
// mach with template and parse
// parse the controls and add it to the page
System.Web.UI.Control ctrlParsedControls = ParseControl(result);
Controls.Add(ctrlParsedControls);
}