ascx dropdownlist

Results 1 to 2 of 2

Thread: ascx dropdownlist

  1. #1
    Join Date
    Dec 1969

    Default ascx dropdownlist

    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>&#060;%@ Register TagPrefix="UserControl" TagName="setMonth" src="../calendar/setMonth.ascx" %&#062; <BR><BR>And display it... <BR><BR>&#060;form runat ="server"&#062; <BR><BR>&#060;UserControl:setMonth id= "setMonth" runat = "Server"/&#062; <BR><BR>form&#062; <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>

  2. #2
    Join Date
    Dec 1969

    Default RE: ascx dropdownlist

    make your value read into a public variable. I&#039;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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts