Solved

need help on ControlID

Posted on 2009-07-06
2
233 Views
Last Modified: 2012-05-07
Hi,

I have the code-behind below that's working just fine when I use it in regular aspx page, but once I put the dropdownlist control "ddlState" in a content page of a master page, it starts giving an error  "Could not find control 'ctl00_secondPageContent_ddlState' in ControlParameter 'state_id'.", where "secondPageContent" is the ID of the contentplaceholder containing the dropdownlist "ddlState".  Can someone tell me how to fix this?

Thanks.
odsLocs.SelectMethod = "SelectOfficeByState";

            ControlParameter stateIDParam = new ControlParameter();

            stateIDParam.ControlID = "ddlState";

            stateIDParam.Name = "state_id";

            stateIDParam.PropertyName = "SelectedValue";

            odsLocs.SelectParameters.Clear();

            odsLocs.SelectParameters.Add(stateIDParam);

            dlLocations.Caption = captionText + "<br /><br />Offices in State:";

            dlLocations.DataSource = odsLocs.Select();

            dlLocations.DataBind();

Open in new window

0
Comment
Question by:WebAppDeveloper
2 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24790246
may be try like this:
DropDownList ddl = (DropDownList)this.FindControl("ddlState");
ControlParameter stateIDParam = new ControlParameter();
stateIDParam.ControlID = ddl.ClientID;

not tested but try and see if that works..
0
 
LVL 13

Accepted Solution

by:
drypz earned 500 total points
ID: 24790886
Hi! Try this one if it works


        DropDownList ddl = this.Master.FindControl("ContentPlaceHolder1").FindControl("ddlState") as DropDownList;

        stateIDParam.ControlID = ddl.ID;

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now