Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

access dropdownlists in a user control from a content page

Posted on 2009-02-20
6
Medium Priority
?
140 Views
Last Modified: 2013-11-26
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


0
Comment
Question by:niceoneishere
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23692965
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; }
}
0
 
LVL 2

Author Comment

by:niceoneishere
ID: 23693841
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

0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23694662
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;
}
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Comment

by:niceoneishere
ID: 23695274
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.

0
 
LVL 11

Accepted Solution

by:
jmwheeler earned 2000 total points
ID: 23696144
This complicates things a bit:  

Add this right below the declaration on your child page

<%@ MasterType VirtualPath="~/Site.master" %>  --Replace Site.Master with the name of your master page.

Then add public propeties in your master page

public string MenuGenderSelectedValue
{
    get { return menu.GenderSelectedValue; }
}

public string MenuSizesSelectedValue
{
    get { return menu.SizesSelectedValue; }
}

Then in your child page call:

string x = Master.MenuGenderSelectedValue;
0
 
LVL 2

Author Closing Comment

by:niceoneishere
ID: 31549258
Thanks once again
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Screencast - Getting to Know the Pipeline
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question