using ascx file within an aspx file

Posted on 2008-11-12
Medium Priority
Last Modified: 2012-05-05
I have about 5 radio buttons and 3 drop downs that are used and are the same in 3 different pages, instead of duplicating the code in all 3 pages, I thought to use a web user control....the problem is I dont know how to source the drop down list within the aspx file.
I have code that populates the drop downs, is it to be in the ascx code behind or the aspx code behind. I need to understand how I can get the two to talk to each other.
VS.NET 2003 - C#

the master page is called default.aspx
and the user control is called settings.ascx

is this possible to do, what am I missing?
all input appreciated.
Question by:solraccheffy
  • 2
LVL 21

Expert Comment

ID: 22943286
you can source the drop down in the ascx itself in the page load...when it's loaded it should also load data...otherwise, you need to create some methods in the ascx like loadData(string dataToLoad) so you can pass parameters from the aspx page...

i.e.  dataToLoad would be a query/ an array/ etc...

you would use the instance that you have on your page to access these message...mycontrol.loadData(textbox.text)  say you're getting your parameter from a user......

Author Comment

ID: 22943332
sorry that was confusing for me...
are you saying its not easy to do this?
would it be more useful to copy and duplicate the code within the aspx pages?
LVL 21

Accepted Solution

silemone earned 200 total points
ID: 22943785
well i'm saying you just need a method that allows loading of the class...

you have a mycontrol.ascx...  <-- that's considered and instance...you give it an id, etc...

<controls: mycontrol id="id" runat="server">

in code-behind:


in the myControl .ascx class

you may want to have a method called loadControl...different from pageload that you can load the control with that takes parameters...

otherwise, it would be simpler to just add to page but that would defeat OOP reusability principals...

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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