473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 4619
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
2
by: Danny Wang | last post by:
HI, I have a dialog (window) with a drop-down list and an OK button. When user clicks the drop-down list, the app need to do some calculation and validation, so I put an Text_on_change event on...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
9
by: Prakash Singh Bhakuni | last post by:
am replacing the default "Browse..." button for input type=file. This works fine except that the form will only submit after the SUBMIT button is clicked twice. Any ideas on why this is happening...
5
by: wizdom | last post by:
I have a simple message board I created a while back. Recently they've asked me to add threading support for messages. so I created a seperate thread page, which gives me each threaded message...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.