User control persistence

ellenraven

New Member
I am creating a drop down list of months that I wold like to reuse throughout the app. I wold like to set the month initially to the current month, and if the user changes the month retain that month on postback. I guess user controls are not persisted the way server controls are, because when I do a postback the user drop down resets to January. <BR><BR>Here is the code that creates the drop down user control:<BR><%@ Import Namespace= "System.Data" %><BR><%@ Import Namespace= "System.Data.SqlClient" %><BR><BR><script language="c#" runat ="server"><BR>protected void Page_Load(Object Sender, EventArgs e){<BR>// Get the month list from an XML file<BR>DataTable objTable;<BR>DataSet objDataset = new DataSet( );<BR>objDataset.ReadXml(Server.MapPath("../xml/MonthList.xml" ));<BR>MonthList.DataSource = objDataset;<BR>MonthList.DataTextField="monthname";<BR>MonthList.DataValueField="monnumber";<BR>MonthList.DataBind( );<BR><BR>//Set to current month on open<BR>if( ! (IsPostBack)){<BR>int newMonth = DateTime.Now.Month;<BR>SetMonthDropDown(newMonth - 1);<BR>}<BR>}<BR>public void SetMonthDropDown(int dtSetDropDate){<BR>MonthList.SelectedIndex = dtSetDropDate;<BR>}<BR></script><BR><!-- User Control Tags --><BR><asp:DropDownList id ="MonthList" runat = "server" /><BR><BR>I create this as a .ascx file and display it on a .aspx page using:<BR><BR><%@ Register TagPrefix="UserControl" TagName="MonthList" src=http://aspmessageboard.com/archive/index.php/"monthList.ascx" %><BR><BR><form runat ="server"><BR><UserControl:MonthList id= "MonthList" runat = "Server"/><BR><asp:button id="Submit" runat = "server" text = "Submit" /><BR></form><BR><BR>This does display the month list just fine, but it does not retain the month when the submit button is clicked. Nor do I know how to get values from the drop down once a selection is made. In some cases I would like to use the selected month as an argument for another process. <BR><BR>All suggestions apprecieated!<BR><BR>Thanks, Dave<BR><BR><BR>
 
Back
Top