ascx dropdownlist

captainnemo

New Member
This code populates a dropdown list of months from an XML file. <BR><BR>protected void Page_Load(Object Sender, EventArgs e){ <BR> // Get the month list from an XML file <BR>if ( ! (IsPostBack)){<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><BR><%@ Register TagPrefix="UserControl" TagName="setMonth" src=http://aspmessageboard.com/archive/index.php/"../calendar/setMonth.ascx" %> <BR><BR>And display it... <BR><BR><form runat ="server"> <BR><BR><UserControl:setMonth id= "setMonth" runat = "Server"/> <BR><BR>form> <BR><BR>The drop down displays fine. And if I select a new month and then submit the value, it does remember the new selection. The page also contains a calendar control - and if you select a new month from the DDL the calendar control should be re-retrieved using the new month value from the list. <BR><BR>If I set a variable to = MonthList.SelectedItem.Text; in the ascx file, the variable is assigned the month name as expected. But this value does not seem to be available to the aspx page that contains it. <BR><BR>Is there a way to grab the value from the a DDL user control so it can be used by the page that it sits on?<BR><BR><BR>make your value read into a public variable. I'm not sure it will work though, never tried it. From what I understand user controls work within there own sandbox and all code inside the control cannot be accessed outside of it and vice versa. One definite solution is to pass your values through the querystring.
 
Back
Top