473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically loading user control based on querystring

I have a site that has MANY different clothing categories. I have a
page set up for displaying the products (productsearch. aspx) when a
user clicks one of the category links on the navigation menu. I would
like to have a different user control that gets loaded as a sub-header
for each category (ie, tee shirts, shoes, backpacks, etc.) The category
user controls include images and links to refined searches specific to
each category.

So far I have succesfully set up the different ASCX files for each
category. I am stuck when it comes to loading them.

The querystring contains a variable named CategoryID. Each of my user
controls are named with the same values used in the CategoryID
variable. How do I load the correct user control?

I am somewhat limited in that I do _NOT_ have access to code-behind.
All code I use must be inline on the ASPX and the ASCX pages.

If any of you have solutions or suggestions I would be very grateful!

Thanks,

five40

Nov 19 '05 #1
5 2781
Curious as to why you say you can't use code-behind.

You basically have a PlaceHolder control declared in your aspx where you
want to user control to appear at runtime. Then you have logic that
determines which user control to load, ten add the user control to the
PlaceHolder's Controls collection. Pretty simple, really.

// to get value from querystring (f you were going to get an integer value
from it):
someValue = Convert.ToInt32 (Request.Params["thisIsFromQuer yString"]);

// Use LoadControl() to instantiate your ascx... like this:
System.Web.UI.C ontrol myUserControlOb ject =
LoadControl("../SomePath/MyUserControl.a scx");
MyPlaceHolder.C ontrols.Add(myU serControlObjec t);

-HTH
<fo**********@g mail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I have a site that has MANY different clothing categories. I have a
page set up for displaying the products (productsearch. aspx) when a
user clicks one of the category links on the navigation menu. I would
like to have a different user control that gets loaded as a sub-header
for each category (ie, tee shirts, shoes, backpacks, etc.) The category
user controls include images and links to refined searches specific to
each category.

So far I have succesfully set up the different ASCX files for each
category. I am stuck when it comes to loading them.

The querystring contains a variable named CategoryID. Each of my user
controls are named with the same values used in the CategoryID
variable. How do I load the correct user control?

I am somewhat limited in that I do _NOT_ have access to code-behind.
All code I use must be inline on the ASPX and the ASCX pages.

If any of you have solutions or suggestions I would be very grateful!

Thanks,

five40

Nov 19 '05 #2

Jeremy S. wrote:
Curious as to why you say you can't use code-behind.

Jeremy-

Thanks for your fast reply. I am going to play with that code and see
if I can get it to work.

The reason I can't use the code behind is that this site was developed
by a company that will not give me access to code behind. Of course I
can pay them to do it but at this point it's sort of a challege and I'd
like to see if I can do it myself.

Nov 19 '05 #3
I've never heard of someone doing both code-behind and code inline (in the
ascx) - but I suppose it might work. In any case that's a lot of
functionality you are adding without proper integration with whatever the
vendor has already supplied in the code behind. Debugging your new
functionality might be difficult or impossible and regression testing will
be nearly impossible. Sure you want to do this? Furthermore, from the
vendor's perspective - you're trying to extend their system without their
knowledge. You might lose their support altogether.

But back to technical considerations. You might be better off dynamically
loading different data (per product category) into just one user control -
rather than having a bunch of user controls dynamically loaded.

Just some random thoughts....

<fo**********@g mail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...

Jeremy S. wrote:
Curious as to why you say you can't use code-behind.

Jeremy-

Thanks for your fast reply. I am going to play with that code and see
if I can get it to work.

The reason I can't use the code behind is that this site was developed
by a company that will not give me access to code behind. Of course I
can pay them to do it but at this point it's sort of a challege and I'd
like to see if I can do it myself.

Nov 19 '05 #4
Actually, the programmers at the vendor are way cool and they have
sorta encouraged me to learn more .NET stuff so I could do some of
these things on my own. Company policy dictaes that I can't access the
code behind but for 'small' things like this they allow some inline
code. Also, they are very busy with big $ clients. I'm a small fish.
They get their monthly hosting fees from me and are happy.

I am going to try to make this work on a staging site. Nothing I can
hurt over there. Currently there is no ASCX for this, I'm adding it so
I won't have to deal with code-behind on that part. One hint they gave
me was to do something page.findcontro l but after reading a few pages
on that I didn't see how it would help.
Jeremy S. wrote:
I've never heard of someone doing both code-behind and code inline (in the
ascx) - but I suppose it might work. In any case that's a lot of
functionality you are adding without proper integration with whatever the
vendor has already supplied in the code behind. Debugging your new
functionality might be difficult or impossible and regression testing will
be nearly impossible. Sure you want to do this? Furthermore, from the
vendor's perspective - you're trying to extend their system without their
knowledge. You might lose their support altogether.

But back to technical considerations. You might be better off dynamically
loading different data (per product category) into just one user control -
rather than having a bunch of user controls dynamically loaded.

Just some random thoughts....


Nov 19 '05 #5
Here's a great article on FindControl(). If you ever need it, you'll benefit
from reading this article.
http://odetocode.com/Articles/116.aspx

Right off I agree with you that I don't see how it could be too useful.
Perhaps it would be safer for your inline code to use FindControl simply as
safety check to help ensure that you aren't attempting to insert a control
with an identical name of a control that already exists there.

But perhaps I"m wandering way off here... still don't know if it's even
possible to do both code -behind and inline. If not the discussion is moot.
Maybe someone else will weigh in here.

<fo**********@g mail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Actually, the programmers at the vendor are way cool and they have
sorta encouraged me to learn more .NET stuff so I could do some of
these things on my own. Company policy dictaes that I can't access the
code behind but for 'small' things like this they allow some inline
code. Also, they are very busy with big $ clients. I'm a small fish.
They get their monthly hosting fees from me and are happy.

I am going to try to make this work on a staging site. Nothing I can
hurt over there. Currently there is no ASCX for this, I'm adding it so
I won't have to deal with code-behind on that part. One hint they gave
me was to do something page.findcontro l but after reading a few pages
on that I didn't see how it would help.
Jeremy S. wrote:
I've never heard of someone doing both code-behind and code inline (in
the
ascx) - but I suppose it might work. In any case that's a lot of
functionality you are adding without proper integration with whatever the
vendor has already supplied in the code behind. Debugging your new
functionality might be difficult or impossible and regression testing
will
be nearly impossible. Sure you want to do this? Furthermore, from the
vendor's perspective - you're trying to extend their system without their
knowledge. You might lose their support altogether.

But back to technical considerations. You might be better off dynamically
loading different data (per product category) into just one user
control -
rather than having a bunch of user controls dynamically loaded.

Just some random thoughts....

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1463
by: Sundaresan | last post by:
I've a form where I load two user controls dynamically. User Control-1 has a no.of dropdowns and based on the selection I typically populate a datagrid in the user control-2, Also the I could be loading a different usercontrol-2 based on the selections in usercontrol-1. Also I thought of passing the selection values through
1
13717
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get and set methods on the user control "editButton.ascx" which work fine. How do i pass parameter into the user controls "c1", "c2" ? Here is a bit of my code that is calling the user control from the
1
3020
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
1
2576
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
4
3115
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
1
6283
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
6
3379
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
7
3195
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb -- UC/ ----- Classic/
5
3077
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc and the specific type of control frequently changes. I have a common event in the base class that each child user control inherits from and that the page wires up and uses to get status from the child user control. I hope all pretty simple and not...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.