Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need help on ControlID

Posted on 2009-07-06
2
Medium Priority
?
241 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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