469,917 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

help, button has to be clicked twice?

Hello, All

I am building two user controls and dynamicly load one them into a
PlaceHolder.
But the button on the user control doesn't work fine. I need to click twice
to fire the event?

Anybody could help me?

Thank you very much

Zelin
Nov 16 '05 #1
8 4372
Hi Zelin
May be you are loading the button more than one time . so make sure the
line where you say New Button is not executed more that once
hope it helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
Hi, Mohamed

Sorry for late reply.

What I am doing is: I create two user controls with buttons which one is
"login" and the other is "after_login".
I load either one of these two user controls in a place holder. The
process is: user opens the page and type in username and password, if it
authorized successfully I remove the "login" control and add the
"after_login" control. The problem occours after removing and adding. It
looks like I load the user control but the button can not capture the
click event at the first time I click it.

Could you help me?

Thank you very much and Merry Chrismas

Zelin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi Zelin
this even increase my suspicion
The scenario you are describing can could make you miss some load( or load
twise)
How do you remove the control, do you use finalize or dispose?
would you post a snippet of your code
Mohamed

Nov 16 '05 #4

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!
Nov 16 '05 #5
Sorry Zelin, couldn't see it right away from what you sent . what you can
do however is to attach the debugger to the aspnet_WP ( worker process of
the aspnet ) and start debugging your code stepping into it line by line to
check what is loaded into your panels and placeholders

Nov 16 '05 #6
Hi, Mohamed

Could you show me how to debug in the way you mentioned?
I go to "debug"-->"process", find the aspnet_wp and attach the script
debugger. then nothing happened. What should I do next?

Thank you very much.

Zelin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
Hi, Mohamed

I've fixed the problem. I think you're right. Eventhough I am not
exactly clear, I guess the problem is when I programmatically created
controls into placeholder, the user control is not really there. I use
Response.redirect to the same page itself instead of raising event from
the user control. The problem is gone.

Whew, Not a bad ending of 2004 for me.

Thank you for your help. Happy new year!
Zelin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8
Hi, Mohamed

I've fixed the problem. I think you're right. Eventhough I am not
exactly clear, I guess the problem is when I programmatically created
controls into placeholder, the user control is not really there. I use
Response.redirect to the same page itself. The problem is gone.

Whew, Not a bad ending of 2004 for me.

Thank you for your help. Happy new year!
Zelin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Danny Wang | last post: by
4 posts views Thread by Jeff User | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.