472,145 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 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 1134
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Phl | last post: by
8 posts views Thread by George Meng | last post: by
1 post views Thread by npverni | last post: by
1 post views Thread by Diffident | last post: by
5 posts views Thread by Gui | last post: by
reply views Thread by Scott Roberts | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.