472,789 Members | 1,049 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Event fails to fire first time in dynamically loaded user control(

I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all the usual stuff of
recreating the usercontrol in the Page Init event.

The 'failure' sequence is as follows:

- select web form button to display the user control
- select user control button, event fires
- select web form button to display user control again
- select user control button, event fails to fire (but postback takes place)
- select user control button again event fires this time

This started as a more complex example with a two 'main' buttons showing and
hiding two user controls but i have reduced it down to this simple example.

Has anyone any ideas on this - i would hate to be reduced to statically
creating the user controls and showing/hiding them!

Nov 19 '05 #1
6 3259
Hi Steve,

I think, this is a "time" problem. The Button's event can only be fired,
when it was recognized. If you load the control, after the RaisePostBackEvent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRender", the OnLoad method is a good
place for the code. Just to check if it's this problem.

cu patrick
"Steve Booth" wrote:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all the usual stuff of
recreating the usercontrol in the Page Init event.

The 'failure' sequence is as follows:

- select web form button to display the user control
- select user control button, event fires
- select web form button to display user control again
- select user control button, event fails to fire (but postback takes place)
- select user control button again event fires this time

This started as a more complex example with a two 'main' buttons showing and
hiding two user controls but i have reduced it down to this simple example.

Has anyone any ideas on this - i would hate to be reduced to statically
creating the user controls and showing/hiding them!

Nov 19 '05 #2
Dear Patrick

I'm afraid i have tried this already. I have been loading the user control
in OnInit (and tried it almost everywhere else - to no avail.

Regards
Steve
"Patrick" wrote:
Hi Steve,

I think, this is a "time" problem. The Button's event can only be fired,
when it was recognized. If you load the control, after the RaisePostBackEvent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRender", the OnLoad method is a good
place for the code. Just to check if it's this problem.

cu patrick
"Steve Booth" wrote:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all the usual stuff of
recreating the usercontrol in the Page Init event.

The 'failure' sequence is as follows:

- select web form button to display the user control
- select user control button, event fires
- select web form button to display user control again
- select user control button, event fails to fire (but postback takes place)
- select user control button again event fires this time

This started as a more complex example with a two 'main' buttons showing and
hiding two user controls but i have reduced it down to this simple example.

Has anyone any ideas on this - i would hate to be reduced to statically
creating the user controls and showing/hiding them!

Nov 19 '05 #3
Hi Steve,

how do you decide which control to load and where? Is this decision
dependant on any postback data?

regards
patrick

"Steve Booth" wrote:
Dear Patrick

I'm afraid i have tried this already. I have been loading the user control
in OnInit (and tried it almost everywhere else - to no avail.

Regards
Steve
"Patrick" wrote:
Hi Steve,

I think, this is a "time" problem. The Button's event can only be fired,
when it was recognized. If you load the control, after the RaisePostBackEvent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRender", the OnLoad method is a good
place for the code. Just to check if it's this problem.

cu patrick
"Steve Booth" wrote:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all the usual stuff of
recreating the usercontrol in the Page Init event.

The 'failure' sequence is as follows:

- select web form button to display the user control
- select user control button, event fires
- select web form button to display user control again
- select user control button, event fails to fire (but postback takes place)
- select user control button again event fires this time

This started as a more complex example with a two 'main' buttons showing and
hiding two user controls but i have reduced it down to this simple example.

Has anyone any ideas on this - i would hate to be reduced to statically
creating the user controls and showing/hiding them!

Nov 19 '05 #4
Dear Patrick

I have pasted the code below, hope it comes out alright i am new to this.....!

I am coming to the conclusion it may be something to do with the uniqueid,
which i am going to investigate now.

The form code is:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="fracas.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"
EnableViewState="False"></asp:PlaceHolder>
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 15px; POSITION:
absolute; TOP: 64px" runat="server"
Text="Show Control 2"></asp:Button>
</form>
</body>
</HTML>

Public Class WebForm2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("WebUserControl3.ascx")
' PlaceHolder1.Controls.Clear()

' PlaceHolder1.Controls.Add(ctl)
'ElseIf Session("w2") Then

'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)
Session("w2") = True

End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)

End If

MyBase.OnInit(e)

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WebUserControl2.ascx.vb" Inherits="fracas.WebUserControl2"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"></asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class

Regards
Steve Booth
"Patrick" wrote:
Hi Steve,

how do you decide which control to load and where? Is this decision
dependant on any postback data?

regards
patrick

"Steve Booth" wrote:
Dear Patrick

I'm afraid i have tried this already. I have been loading the user control
in OnInit (and tried it almost everywhere else - to no avail.

Regards
Steve
"Patrick" wrote:
Hi Steve,

I think, this is a "time" problem. The Button's event can only be fired,
when it was recognized. If you load the control, after the RaisePostBackEvent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRender", the OnLoad method is a good
place for the code. Just to check if it's this problem.

cu patrick
"Steve Booth" wrote:

> I have a web form with a button and a placeholder, the button adds a user
> control to the placeholder (and removes any existing controls). The user
> control contains a single button. I have done all the usual stuff of
> recreating the usercontrol in the Page Init event.
>
> The 'failure' sequence is as follows:
>
> - select web form button to display the user control
> - select user control button, event fires
> - select web form button to display user control again
> - select user control button, event fails to fire (but postback takes place)
> - select user control button again event fires this time
>
> This started as a more complex example with a two 'main' buttons showing and
> hiding two user controls but i have reduced it down to this simple example.
>
> Has anyone any ideas on this - i would hate to be reduced to statically
> creating the user controls and showing/hiding them!
>
>
>

Nov 19 '05 #5
Hi Steve,

for me, it is clear that it is the "Button1.Click" event which, when fired,
adds dynamically an usercontrol. It really has something to do with the
uniqueID, because ASP.Net can only create that ID based on a valid
control-hierarchy and this hierarchy MUST persist upon PostBack. That means,
the clicked button does not have the same ID when it checks whether to fire
the click event or not. You must imagin, the button just does a request of
it's UniqueID; if it's set to a value the button was clicked otherwise not.

All you have to do is to put the code, where the usercontrol is loaded, into
the Init event of your Page. Look here:

Public Class WebForm1

....

Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Init

PlaceHolder1.Controls.Clear ()
If (Session ("w1") Is Not Nothing) Then
PlaceHolder1.Controls.Add (LoadControl ("~/MyUserControl1.ascx"))
ElseIf (Session ("w2") Is Not Nothing) Then
PlaceHolder1.Controls.Add (LoadControl ("~/MyUserControl2.ascx"))
' ElseIf ... And so on ...
End If

....

End Sub

End Class

Or, even better, into the InitializeComponent. Because that's what it's for ;)
However, loading controls dynamically in a Click event of a button is
generally a bad idea; except you know exactly(!) what you are doing.

Hope that helps
Patrick

"Steve Booth" wrote:
Dear Patrick

I have pasted the code below, hope it comes out alright i am new to this.....!

I am coming to the conclusion it may be something to do with the uniqueid,
which i am going to investigate now.

The form code is:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="fracas.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"
EnableViewState="False"></asp:PlaceHolder>
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 15px; POSITION:
absolute; TOP: 64px" runat="server"
Text="Show Control 2"></asp:Button>
</form>
</body>
</HTML>

Public Class WebForm2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("WebUserControl3.ascx")
' PlaceHolder1.Controls.Clear()

' PlaceHolder1.Controls.Add(ctl)
'ElseIf Session("w2") Then

'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)
Session("w2") = True

End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)

End If

MyBase.OnInit(e)

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WebUserControl2.ascx.vb" Inherits="fracas.WebUserControl2"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"></asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class

Regards
Steve Booth
"Patrick" wrote:
Hi Steve,

how do you decide which control to load and where? Is this decision
dependant on any postback data?

regards
patrick

"Steve Booth" wrote:
Dear Patrick

I'm afraid i have tried this already. I have been loading the user control
in OnInit (and tried it almost everywhere else - to no avail.

Regards
Steve
"Patrick" wrote:

> Hi Steve,
>
> I think, this is a "time" problem. The Button's event can only be fired,
> when it was recognized. If you load the control, after the RaisePostBackEvent
> should have been called the control will never find out, whether s.o. clicked
> on it or not.
>
> Try to add the control before "OnPreRender", the OnLoad method is a good
> place for the code. Just to check if it's this problem.
>
> cu patrick
>
>
> "Steve Booth" wrote:
>
> > I have a web form with a button and a placeholder, the button adds a user
> > control to the placeholder (and removes any existing controls). The user
> > control contains a single button. I have done all the usual stuff of
> > recreating the usercontrol in the Page Init event.
> >
> > The 'failure' sequence is as follows:
> >
> > - select web form button to display the user control
> > - select user control button, event fires
> > - select web form button to display user control again
> > - select user control button, event fails to fire (but postback takes place)
> > - select user control button again event fires this time
> >
> > This started as a more complex example with a two 'main' buttons showing and
> > hiding two user controls but i have reduced it down to this simple example.
> >
> > Has anyone any ideas on this - i would hate to be reduced to statically
> > creating the user controls and showing/hiding them!
> >
> >
> >

Nov 19 '05 #6
Hi Patrick

Not at work at present to check this out but (from memory) the main problem
is that when selecting a button to change the page layout the PageInit and
PageLoad events are fired before the button event. On clearing/adding the new
control(s) in the button event the page load for the new controls is fired -
this must be when it gets the wrong uniqueid (ie mismatches the current
hierarchy).

Interestingly - though i did not mention it in the post because i thought it
would it too confusing - i do have a case where this does work! I am have
tried very hard to determine the difference but could not. But this was
before the uniqueid possibility was raised. I look forward to getting to work
tomorrow to look at this!

At the limit i shall raise an incident with Microsoft - about £70 by email
and probably worth it.
Regards
Steve
"Patrick" wrote:
Hi Steve,

for me, it is clear that it is the "Button1.Click" event which, when fired,
adds dynamically an usercontrol. It really has something to do with the
uniqueID, because ASP.Net can only create that ID based on a valid
control-hierarchy and this hierarchy MUST persist upon PostBack. That means,
the clicked button does not have the same ID when it checks whether to fire
the click event or not. You must imagin, the button just does a request of
it's UniqueID; if it's set to a value the button was clicked otherwise not.

All you have to do is to put the code, where the usercontrol is loaded, into
the Init event of your Page. Look here:

Public Class WebForm1

...

Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Init

PlaceHolder1.Controls.Clear ()
If (Session ("w1") Is Not Nothing) Then
PlaceHolder1.Controls.Add (LoadControl ("~/MyUserControl1.ascx"))
ElseIf (Session ("w2") Is Not Nothing) Then
PlaceHolder1.Controls.Add (LoadControl ("~/MyUserControl2.ascx"))
' ElseIf ... And so on ...
End If

...

End Sub

End Class

Or, even better, into the InitializeComponent. Because that's what it's for ;)
However, loading controls dynamically in a Click event of a button is
generally a bad idea; except you know exactly(!) what you are doing.

Hope that helps
Patrick

"Steve Booth" wrote:
Dear Patrick

I have pasted the code below, hope it comes out alright i am new to this.....!

I am coming to the conclusion it may be something to do with the uniqueid,
which i am going to investigate now.

The form code is:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="fracas.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"
EnableViewState="False"></asp:PlaceHolder>
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 15px; POSITION:
absolute; TOP: 64px" runat="server"
Text="Show Control 2"></asp:Button>
</form>
</body>
</HTML>

Public Class WebForm2
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("WebUserControl3.ascx")
' PlaceHolder1.Controls.Clear()

' PlaceHolder1.Controls.Add(ctl)
'ElseIf Session("w2") Then

'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)
Session("w2") = True

End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("WebUserControl2.ascx")
PlaceHolder1.Controls.Clear()

PlaceHolder1.Controls.Add(ctl)

End If

MyBase.OnInit(e)

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="WebUserControl2.ascx.vb" Inherits="fracas.WebUserControl2"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"></asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class

Regards
Steve Booth
"Patrick" wrote:
Hi Steve,

how do you decide which control to load and where? Is this decision
dependant on any postback data?

regards
patrick

"Steve Booth" wrote:

> Dear Patrick
>
> I'm afraid i have tried this already. I have been loading the user control
> in OnInit (and tried it almost everywhere else - to no avail.
>
> Regards
> Steve
>
>
> "Patrick" wrote:
>
> > Hi Steve,
> >
> > I think, this is a "time" problem. The Button's event can only be fired,
> > when it was recognized. If you load the control, after the RaisePostBackEvent
> > should have been called the control will never find out, whether s.o. clicked
> > on it or not.
> >
> > Try to add the control before "OnPreRender", the OnLoad method is a good
> > place for the code. Just to check if it's this problem.
> >
> > cu patrick
> >
> >
> > "Steve Booth" wrote:
> >
> > > I have a web form with a button and a placeholder, the button adds a user
> > > control to the placeholder (and removes any existing controls). The user
> > > control contains a single button. I have done all the usual stuff of
> > > recreating the usercontrol in the Page Init event.
> > >
> > > The 'failure' sequence is as follows:
> > >
> > > - select web form button to display the user control
> > > - select user control button, event fires
> > > - select web form button to display user control again
> > > - select user control button, event fails to fire (but postback takes place)
> > > - select user control button again event fires this time
> > >
> > > This started as a more complex example with a two 'main' buttons showing and
> > > hiding two user controls but i have reduced it down to this simple example.
> > >
> > > Has anyone any ideas on this - i would hate to be reduced to statically
> > > creating the user controls and showing/hiding them!
> > >
> > >
> > >

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joel Reinford | last post by:
I am working on an ASP.NET web app. One of the pages will be using several user controls. The controls will be loaded dynamically based on SQL Server data. I need to be able to retrieve the...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
0
by: Thanh Nguyen | last post by:
Hi everyone, I'm encountering a very weird problem, I have spent the last 3 days trying to figure out how to fix but there is still no clue. Here is the problem: I define 2 WebUserControls: -...
0
by: Tonix | last post by:
This problem was originated by Thanh Nguyen. Your help is appreciated. Thanks. The original text is: Hi everyone, I'm encountering a very weird problem, I have spent the last 3 days trying to...
1
by: Raed Sawalha | last post by:
I am trying to sort a DataGrid in a user control that is programatically loaded when a link button is clicked. UC1 is loaded onto Page1.aspx after clicking a link button. No problem, loads fine....
3
by: JB McMichael | last post by:
I have an aspx page that based on a query loads a user control dynamically. The aspx page is simple, just a place holder, the code behind queries a table that stores the names of the ascx files. ...
1
by: jason | last post by:
Hi, I have a web page template that dynamically loading user controls (header, content, footer ..etc) based on user's selections. I wonder if it will impact the scalability and performance of...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
0
by: dethadi | last post by:
Hi: I am loading a user control on postback of a link click event. Now, when I try to retrieve the selected values in this control on button click event (next postback), I am not able to. Can you...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.