Link to home
Start Free TrialLog in
Avatar of Tammu
Tammu

asked on

access dropdownlists in a user control from a content page

Hi All,
i have a user control called MyMenu.ascx. In it i have 2 dropdownlist boxes. one is depending on the other. what i mean is the firt dropdown box has text like ALL, Men, Women and the second DDL has ALL, S, M, XL, XXL.
basically if i select one item in the first DDL ( say i select Men) then the second DDL displays all the available options for Men. here is the code for both the DDL in MyMenu.ascx

<div style="float: left; margin-left: 2px;">
        <span class="text">View By Gender:</span><br />
        <asp:dropdownlist id="DDLgender" runat="server" autopostback="true">
            <asp:listitem value="-1">All</asp:listitem>
            <asp:listitem value="1">Men</asp:listitem>
            <asp:listitem value="2">Women</asp:listitem>
        </asp:dropdownlist><br />
        <br />
        <span class="text" style="margin-left: 2px;">View by Size:</span><br />
        <asp:dropdownlist id="DDLsizes" runat="server" autopostback="true">
            <asp:listitem value="-1">All</asp:listitem>
        </asp:dropdownlist>
    </div>

now what i want is , how can i access the first and second DDL selected values in content page. i am hope i am clear in explaining.

Thanks I appreciate it


Avatar of jmwheeler
jmwheeler

You should add public properties to your control to expose the values:

public string GenderSelectedValue
{
    get { return DDLgender.SelectedValue; }
}

public string SizesSelectedValue
{
    get { return DDLsizes.SelectedValue; }
}
Avatar of Tammu

ASKER

Hello Sir,
Thanks for replying back, one newbie question: i have declared the above public strings in the user control and put a breakpoint at  

get { return DDLgender.SelectedValue; }

to see if the selected value is getting passed to the string. when i ran page it does not hit the breakpoint, nothing is getting passed.

can you please tell me where i am making the mistake sir
Thanks one again

It will never hit the breakpoint unless you try to access the value from your page.

ex.

protected void Page_Load(object sender, EventArgs e)
{
     //Where 'menu' is the id for your custom control
     string x = menu.GenderSelectedValue;
}
Avatar of Tammu

ASKER

Ok Sir,
i have one more question, the content page where i want to access these DDL values is based on nested master page. the user control where the DDL are is in the parent master page. so how can i access the DDL values from the content page by the below code

string x = menu.GenderSelectedValue;

if i try that i cant find MyMenu (which is the user control)

any advice or sample sir.
Thanks once again i appreciate it.

ASKER CERTIFIED SOLUTION
Avatar of jmwheeler
jmwheeler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tammu

ASKER

Thanks once again