mgasft
asked on
call asp.net usercontrol form asp.net usercontrol
Hi
I am just starting a new application (asp.net/vb.net) and was wondering if I could do it in a different way as I usually do: Instead of the user creating dozens of pages I would like them to see only a default.aspx with dynamically loaded UserControls.
Thing is I have 3 distintive areas on my page: A top menu, a side menu and the content area.
My question is the following; Can I call a UserControl from another UserControl?
EG Clicking on the top menu (ascx) would load a sidebar menu (another ascx), clicking on the sidebar would open another ascx in the content area.
Is this a feasable option?
I seem to rember seeing applications whre the user always stayed on the default.aspx.
Thanks, Mike
I am just starting a new application (asp.net/vb.net) and was wondering if I could do it in a different way as I usually do: Instead of the user creating dozens of pages I would like them to see only a default.aspx with dynamically loaded UserControls.
Thing is I have 3 distintive areas on my page: A top menu, a side menu and the content area.
My question is the following; Can I call a UserControl from another UserControl?
EG Clicking on the top menu (ascx) would load a sidebar menu (another ascx), clicking on the sidebar would open another ascx in the content area.
Is this a feasable option?
I seem to rember seeing applications whre the user always stayed on the default.aspx.
Thanks, Mike
ASKER
Hi Bob
Please have a look athe these screenshots:
http://www.algarveweb.com/list.jpg
http://www.algarveweb.com/edit.jpg
I am using master pages right now.
I have 2 points where I wish to improve the application:
1 - get rid of querystrings, meaning that the user can not tamper with them.
2 - alway show default.aspx as current page so the user can not go to different pages.
Thanks, Mike.
Please have a look athe these screenshots:
http://www.algarveweb.com/list.jpg
http://www.algarveweb.com/edit.jpg
I am using master pages right now.
I have 2 points where I wish to improve the application:
1 - get rid of querystrings, meaning that the user can not tamper with them.
2 - alway show default.aspx as current page so the user can not go to different pages.
Thanks, Mike.
ASKER
Some more info:
This is a multi company/multi user application, therefore the need for addionatal security.
I have tried in the meantime a frameset with a centered content page, but of course there the user can always righ click and find out the path and name of the page.
Mike
This is a multi company/multi user application, therefore the need for addionatal security.
I have tried in the meantime a frameset with a centered content page, but of course there the user can always righ click and find out the path and name of the page.
Mike
Mike,
I like to have the Menu in the master page, and then have the target for the navigation be to a page that uses the same master page, and displays its contents in the ContentPlaceHolder--no frameset, no user controls.
bob
I like to have the Menu in the master page, and then have the target for the navigation be to a page that uses the same master page, and displays its contents in the ContentPlaceHolder--no frameset, no user controls.
bob
ASKER
Bob
I am not user that I understand.
This the curent page layout: http://www.algarveweb.com/explorer.jpg
As you can see I use master pages already with 3 ContenPlaceHolders: Top, Left and Content.
But when I navigate it always shows the current page name eg. LIST_main_add.aspx, which I try to avoid.
Mike
I am not user that I understand.
This the curent page layout: http://www.algarveweb.com/explorer.jpg
As you can see I use master pages already with 3 ContenPlaceHolders: Top, Left and Content.
But when I navigate it always shows the current page name eg. LIST_main_add.aspx, which I try to avoid.
Mike
ASKER
user = sure
ASKER
How can I load a user control from inside a user control?
That is an interesting requirement, and one which I don't have a ready answer for.
Bob
Bob
ASKER
I got this working from inside uc1.ascx loaded in a Placeholder:
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
'my_plc.Controls.Clear() GIVES ERROR
Dim my_control As Control = Page.LoadControl("uc2.ascx ")
my_plc.Controls.Add(my_con trol)
When I try to clear the Placeholder I get:
Object reference not set to an instance of an object.
Dim my_control As Control = Page.LoadControl("uc2.ascx ")
Without the Clear id adds to the current content in the Placeholder, whci of course is wrong
I think we are very close now, any ideas?
Mike
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
'my_plc.Controls.Clear() GIVES ERROR
Dim my_control As Control = Page.LoadControl("uc2.ascx
my_plc.Controls.Add(my_con
When I try to clear the Placeholder I get:
Object reference not set to an instance of an object.
Dim my_control As Control = Page.LoadControl("uc2.ascx
Without the Clear id adds to the current content in the Placeholder, whci of course is wrong
I think we are very close now, any ideas?
Mike
ASKER
I CAN CLEAR THE PACEHOLDER
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
my_plc.Controls.Clear()
OR ADD TO THE PLACHOLDER
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
Dim my_control As Control = Page.LoadControl("uc2.ascx ")
my_plc.Controls.Add(my_con trol)
BUT NOT BOTH
Mike
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
my_plc.Controls.Clear()
OR ADD TO THE PLACHOLDER
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
Dim my_control As Control = Page.LoadControl("uc2.ascx
my_plc.Controls.Add(my_con
BUT NOT BOTH
Mike
ASKER
Strange, it works id used directly in aspx mas not in ascx
1) Where is the PlaceHolder defined? On the master page?
2) Where are you trying to call this from?
Bob
2) Where are you trying to call this from?
Bob
ASKER
1) No master page, just simple aspx.
2) Inside the first ascx.
2) Inside the first ascx.
ASKER
<%@ Page Language="VB" AutoEventWireup="false" Debug="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Src="uc1.ascx" TagName="uc1" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Remove aspx" /><br />
<br />
<asp:PlaceHolder ID="plc" runat="server"></asp:Place Holder>
</div>
</form>
</body>
</html>
<%@ Register Src="uc1.ascx" TagName="uc1" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Remove aspx" /><br />
<br />
<asp:PlaceHolder ID="plc" runat="server"></asp:Place
</div>
</form>
</body>
</html>
ASKER
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim my_control As Control = Page.LoadControl("uc1.ascx ")
plc.Controls.Add(my_contro l)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim my_control As Control = Page.LoadControl("uc1.ascx ")
plc.Controls.Add(my_contro l)
plc.Controls.Clear()
Dim my_control2 As Control = Page.LoadControl("uc2.ascx ")
plc.Controls.Add(my_contro l2)
End Sub
End Class
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim my_control As Control = Page.LoadControl("uc1.ascx
plc.Controls.Add(my_contro
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim my_control As Control = Page.LoadControl("uc1.ascx
plc.Controls.Add(my_contro
plc.Controls.Clear()
Dim my_control2 As Control = Page.LoadControl("uc2.ascx
plc.Controls.Add(my_contro
End Sub
End Class
ASKER
<%@ Control Language="VB" AutoEventWireup="false" Debug="true" CodeFile="uc1.ascx.vb" Inherits="uc1" %>
uc1<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Remove ascx" />
uc1<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Remove ascx" />
ASKER
Partial Class uc1
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
my_plc.Controls.Clear() ' GIVES ERROR
Dim my_control As Control = Page.LoadControl("uc2.ascx ")
my_plc.Controls.Add(my_con trol)
End Sub
End Class
Inherits System.Web.UI.UserControl
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
my_plc.Controls.Clear() ' GIVES ERROR
Dim my_control As Control = Page.LoadControl("uc2.ascx
my_plc.Controls.Add(my_con
End Sub
End Class
ASKER
the 2nd ascx is just empty-
ASKER
The importna code is in Partial Class uc1
ASKER
I have uploded my code here
http://www.algarveweb.com/my_user_control.rar
hope that helps to see what i need
Mike
http://www.algarveweb.com/my_user_control.rar
hope that helps to see what i need
Mike
ASKER
Good morning
I god this working inside the 1st ascx:
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
Dim my_control As Control = Page.LoadControl("uc2.ascx ")
my_plc.Controls.Add(my_con trol)
my_plc.Controls.RemoveAt(0 )
If I remove the control 1st and then add it dows not work!
When I add 1st and the remove it works!
Very strange!!
Mike
I god this working inside the 1st ascx:
Dim my_plc As New PlaceHolder
my_plc = Page.FindControl("plc")
Dim my_control As Control = Page.LoadControl("uc2.ascx
my_plc.Controls.Add(my_con
my_plc.Controls.RemoveAt(0
If I remove the control 1st and then add it dows not work!
When I add 1st and the remove it works!
Very strange!!
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) You can load a user control from another user control
2) It would probably help to know what kind of UI that you are trying to achieve.
3) There might be some master page magic that would alleviate that requirement of user controls.
Bob