E
et
How do I load a user control in a web form first, so that the web form's
page_load acts according to events on the user control?
In my code below, I have a user control at the top of every web form, in a
panel. I have 2 other panels on the web forms, to be shown individually
depending on what the user clicks on the user control. However, when the
button on the user control is clicked, the web form page_load fires first,
then the control's page_load, then the event of the button click in the user
control fires last, so there is no response from the web form because it
has already been loaded. What do I do about this, I've seen similar
dilemmas in this newsgroup and find hundreds of articles in ms, but none
that solve this one, unless I'm just not putting the pieces together.
Thanks for any help, advice!
index.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb"
Inherits="WebForm1"%>
<%@ Register TagPrefix="uc1" TagName="ucHeader" Src="ucHeader.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body >
<form id=frm1 runat=server>
<asp
anel id=Panel1 runat="server">
<uc1:ucHeader id=UcHeader1 runat="server"></uc1:ucHeader>
</asp
anel>
<asp
anel id=Panel2 runat="server">Panel 2</asp
anel>
<asp
anel id=Panel3 runat="server">Panel 3</asp
anel>
</form>
</body>
</HTML>
index.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
if not ispostback then
if ucHeader.value = true then
Panel2.Visible = True
panel3.Visible = False
else
panel2.Visible=False
panel3.Visible = true
End If
end if
End Sub
ucHeader.ascx
<%@ Control Language="vb" classname="ucHeader" AutoEventWireup="false"
Codebehind="ucHeader.ascx.vb" Inherits="WMIS.ucHeader"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<TABLE id=header borderColor=black cellSpacing=0 cellPadding=0 width="100%">
<TR align=center>
<TD><asp:button id=btnABC Font-Bold="True" Text="Show Panel 1"
runat="server"></asp:button></td>
<TD><asp:button id=btnDEF Font-Bold="True" Text="Show Panel 2"
runat="server"></asp:button></td></tr>
</TABLE>
page_load acts according to events on the user control?
In my code below, I have a user control at the top of every web form, in a
panel. I have 2 other panels on the web forms, to be shown individually
depending on what the user clicks on the user control. However, when the
button on the user control is clicked, the web form page_load fires first,
then the control's page_load, then the event of the button click in the user
control fires last, so there is no response from the web form because it
has already been loaded. What do I do about this, I've seen similar
dilemmas in this newsgroup and find hundreds of articles in ms, but none
that solve this one, unless I'm just not putting the pieces together.
Thanks for any help, advice!
index.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb"
Inherits="WebForm1"%>
<%@ Register TagPrefix="uc1" TagName="ucHeader" Src="ucHeader.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body >
<form id=frm1 runat=server>
<asp
<uc1:ucHeader id=UcHeader1 runat="server"></uc1:ucHeader>
</asp
<asp
<asp
</form>
</body>
</HTML>
index.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
if not ispostback then
if ucHeader.value = true then
Panel2.Visible = True
panel3.Visible = False
else
panel2.Visible=False
panel3.Visible = true
End If
end if
End Sub
ucHeader.ascx
<%@ Control Language="vb" classname="ucHeader" AutoEventWireup="false"
Codebehind="ucHeader.ascx.vb" Inherits="WMIS.ucHeader"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<TABLE id=header borderColor=black cellSpacing=0 cellPadding=0 width="100%">
<TR align=center>
<TD><asp:button id=btnABC Font-Bold="True" Text="Show Panel 1"
runat="server"></asp:button></td>
<TD><asp:button id=btnDEF Font-Bold="True" Text="Show Panel 2"
runat="server"></asp:button></td></tr>
</TABLE>