login.ascx:
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="Login.ascx.cs" Inherits="idealoneview.Login"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<meta content="False" name="vs_showGrid">
<asp:panel id="Panel1" BorderWidth="0" BorderStyle="Solid"
BorderColor="Navy" HorizontalAlign="Left"
Height="131px" Width="176px" runat="server">
<asp:Label id="lblUName" runat="server">User Name:</asp:Label>
<asp:TextBox id="txtUName" Width="160px" runat="server"></asp:TextBox>
<asp:Label id="lblPassword" Width="72px" runat="server">Password:
</asp:Label>
<asp:TextBox id="txtPassword" Width="160px" runat="server"
TextMode="Password"></asp:TextBox>
<asp:Button id="btnLogin" Width="88px" runat="server"
Text="Login"></asp:Button>
<asp:Button id="btnRegister" Width="64px" runat="server"
Text="Register"></asp:Button>
<asp:Label id="lblMessage" Width="160px" runat="server"
ForeColor="Red"></asp:Label>
</asp:panel>
userpanel.ascx
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="UserPanel.ascx.cs" Inherits="idealoneview.UserPanel"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls"
Assembly="Microsoft.Web.UI.WebControls" %>
<P>
<asp:Label id="Label1" runat="server"></asp:Label>
<asp:Button id="btnLogout" Width="80px" runat="server"
Text="Logout"></asp:Button>
<asp:Label id="Label2" runat="server">Change Setting</asp:Label>
<asp:Button id="btnAdmin" Width="80px" runat="server"
Text="Admin"></asp:Button></P>
default.aspx:
...
public class DefaultForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder HolderTreeview;
protected System.Web.UI.WebControls.PlaceHolder HolderLogin;
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected Login login1;
protected UserPanel userpanel1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// add login module dynamicly
//control1 = LoadControl("Modules\\Login\\Login.ascx");
// Control ctr = LoadControl("Login.ascx");
// login1 = ctr as Login;
// call function to load all modules. The loading logic is
implemented in
// this function.
Modules_Load();
this.GetPostBackEventReference(this.HolderLogin);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void login1_SuccessLogin(object sender, EventArgs e)
{
// After user login, reload the login area of the page.
Modules_Load();
}
private void Modules_Load()
{
// loading logic here
// Check the user status and privileges and then load the
// proper modules for the current user.
if(Session["username"] == null)
{
//User not login yet.
//load the UI for login area
// Load a control, cast and store it into login1 property.
Control ctr = LoadControl("Login.ascx");
login1 = ctr as Login;
// Add event control
this.login1.SuccessLogin +=new EventHandler(login1_SuccessLogin);
HolderLogin.Controls.Clear();
HolderLogin.Controls.Add(login1);
}
else
{
//Authorized user. After successful login scenerio
Control ctr = LoadControl("UserPanel.ascx");
userpanel1 = ctr as UserPanel;
this.userpanel1.LogoutClicked +=new
EventHandler(userpanel1_LogoutClicked);
//load the UI after login area
HolderLogin.Controls.Clear();
//Response.Write("hi, this is message after login.");
HolderLogin.Controls.Add(userpanel1);
//add treeview
TreeView1 = new Microsoft.Web.UI.WebControls.TreeView();
HolderTreeview.Controls.Add(TreeView1);
}
}
protected override bool OnBubbleEvent(object sender, EventArgs e)
{
if(sender is Button)
{
Response.Write("button bubble event raised<br>");
Modules_Load();
}
return true;
}
private void userpanel1_LogoutClicked(object sender, EventArgs e)
{
Response.Write("LogoutClicked Event fired.<br>");
Modules_Load();
}
}
...
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!