473,216 Members | 1,266 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Confusion in testing dynamic loading of controls

Ok I have created a small testbed site for testing and I am have a problem
with the terms Usercontrol, Webcontrol, etc.

What I need to do in the long run is have a page using AJAX and having
dynamically loaded controls on the page.

So what I did was first create a page with two buttons. First button will
load a Label control into a placeholder. After execution and clicking the
button the label shows in the page.

Next I create a WebUserControl (now is that a UserControl or a WebControl
????) do the same with the other button. The WebUserControl has just a
Label so it should show the same as the first button behaviour I would
think. But nothing shows in the placeholder.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Session("Type") = "One"
Dim ctl As WebControl
Dim lbl As New Label
lbl.Text="This is label1"
ctl = lbl
ctl.Visible = True
Me.PlaceHolder1.Controls.Clear()
Me.PlaceHolder1.Controls.Add(ctl)
End Sub
Above shows the label no problem
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Session("Type") = "Two"
Dim ctl As UserControl
ctl = New WebUserControl2
ctl.Visible = True
Me.PlaceHolder1.Controls.Clear()
Me.PlaceHolder1.Controls.Add(ctl)
End Sub
This code shows nothing on the resulting page.

I need to get this working with AJAX but cannot get a simple WebUserControl
on the page.

Any ideas??

Lloyd Sheen

Mar 26 '07 #1
2 1189
On Mar 26, 10:24 pm, "Lloyd Sheen" <a...@b.cwrote:
Ok I have created a small testbed site for testing and I am have a problem
with the terms Usercontrol, Webcontrol, etc.
[snip]

http://ajaxwidgets.com/AllControlsSa...rControls.aspx
or...
http://ajaxwidgets.com/AllControlsSa...wAdvanced.aspx

Click the "View code" button to see the code...

Mar 26 '07 #2
Hi Llyod,

A UserControl is a visually composed control (typically stored in an .ASCX
markup file). A WebControl refers to a full ASP.NET server control like
Label, TextBox, GridView etc. but can also be a custom created control -
anything that inherits from Control qualifies.

UserControls and WebControls load differently because UserControls typically
are loaded by their filename with ASP.NET handling the parsing of the
control at runtime and expanding the template and then instantiating it,
whereas a WebControl is an already compiled control that can be just
instantiated.

So in the second example, what are you actually trying to do? If you're
trying to load a User Control you should use:

UserControl Ctl = this.LoadControl("SomeControl.ascx");

to ensure you get the control loaded properly.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com/weblog
"Lloyd Sheen" <a@b.cwrote in message
news:EF**********************************@microsof t.com...
Ok I have created a small testbed site for testing and I am have a problem
with the terms Usercontrol, Webcontrol, etc.

What I need to do in the long run is have a page using AJAX and having
dynamically loaded controls on the page.

So what I did was first create a page with two buttons. First button will
load a Label control into a placeholder. After execution and clicking the
button the label shows in the page.

Next I create a WebUserControl (now is that a UserControl or a WebControl
????) do the same with the other button. The WebUserControl has just a
Label so it should show the same as the first button behaviour I would
think. But nothing shows in the placeholder.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Session("Type") = "One"
Dim ctl As WebControl
Dim lbl As New Label
lbl.Text="This is label1"
ctl = lbl
ctl.Visible = True
Me.PlaceHolder1.Controls.Clear()
Me.PlaceHolder1.Controls.Add(ctl)
End Sub
Above shows the label no problem
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Session("Type") = "Two"
Dim ctl As UserControl
ctl = New WebUserControl2
ctl.Visible = True
Me.PlaceHolder1.Controls.Clear()
Me.PlaceHolder1.Controls.Add(ctl)
End Sub
This code shows nothing on the resulting page.

I need to get this working with AJAX but cannot get a simple
WebUserControl on the page.

Any ideas??

Lloyd Sheen
Mar 27 '07 #3

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

Similar topics

0
by: Phl | last post by:
Hi, I am trying to create an webform which loads usercontrols dyanamically. I know exactly what to load for some of these controls but for some, I dont want to load it until the user has press a...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
8
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
1
by: npverni | last post by:
I have a fairly complex form that needs to load and maintain the state of several different dynamic user controls. Here is the workflow: 1) A series of editable user controls (each containing...
1
by: Diffident | last post by:
Hello All, I am trying to add dynamic controls onto my page and here is how I am doing that. I have a page which has a button called as "AddMoreControls" and in this button's event handler I...
1
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
5
by: Gui | last post by:
Hi, I'm working in C# .net 2005 with Ajax. I have a page that loads dynamic user controls depending on the scenario. In those user controls, I create dynamic linkbuttons. The user controls are...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.