473,888 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3387
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 RaisePostBackEv ent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRende r", 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 RaisePostBackEv ent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRende r", 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 RaisePostBackEv ent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRende r", 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="Web Form2.aspx.vb"
Inherits="fraca s.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r id="PlaceHolder 1" 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.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on

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

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

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("We bUserControl3.a scx")
' PlaceHolder1.Co ntrols.Clear()

' PlaceHolder1.Co ntrols.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.
InitializeCompo nent()
End Sub

#End Region

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

End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)
Session("w2") = True

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

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)

End If

MyBase.OnInit(e )

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Web UserControl2.as cx.vb" Inherits="fraca s.WebUserContro l2"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"> </asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.U serControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

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

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

#End Region

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

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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 RaisePostBackEv ent
should have been called the control will never find out, whether s.o. clicked
on it or not.

Try to add the control before "OnPreRende r", 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.Cl ick" 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.Co ntrols.Clear ()
If (Session ("w1") Is Not Nothing) Then
PlaceHolder1.Co ntrols.Add (LoadControl ("~/MyUserControl1. ascx"))
ElseIf (Session ("w2") Is Not Nothing) Then
PlaceHolder1.Co ntrols.Add (LoadControl ("~/MyUserControl2. ascx"))
' ElseIf ... And so on ...
End If

....

End Sub

End Class

Or, even better, into the InitializeCompo nent. 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="Web Form2.aspx.vb"
Inherits="fraca s.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r id="PlaceHolder 1" 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.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on

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

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

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("We bUserControl3.a scx")
' PlaceHolder1.Co ntrols.Clear()

' PlaceHolder1.Co ntrols.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.
InitializeCompo nent()
End Sub

#End Region

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

End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)
Session("w2") = True

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

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)

End If

MyBase.OnInit(e )

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Web UserControl2.as cx.vb" Inherits="fraca s.WebUserContro l2"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"> </asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.U serControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

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

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

#End Region

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

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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 RaisePostBackEv ent
> should have been called the control will never find out, whether s.o. clicked
> on it or not.
>
> Try to add the control before "OnPreRende r", 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.Cl ick" 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.Co ntrols.Clear ()
If (Session ("w1") Is Not Nothing) Then
PlaceHolder1.Co ntrols.Add (LoadControl ("~/MyUserControl1. ascx"))
ElseIf (Session ("w2") Is Not Nothing) Then
PlaceHolder1.Co ntrols.Add (LoadControl ("~/MyUserControl2. ascx"))
' ElseIf ... And so on ...
End If

...

End Sub

End Class

Or, even better, into the InitializeCompo nent. 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="Web Form2.aspx.vb"
Inherits="fraca s.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r id="PlaceHolder 1" 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.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents PlaceHolder1 As System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on

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

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

'If Session("w3") Then
' Dim ctl As WebUserControl3 = LoadControl("We bUserControl3.a scx")
' PlaceHolder1.Co ntrols.Clear()

' PlaceHolder1.Co ntrols.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.
InitializeCompo nent()
End Sub

#End Region

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

End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)
Session("w2") = True

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

If Session("w2") Then
Dim ctl As WebUserControl2 = LoadControl("We bUserControl2.a scx")
PlaceHolder1.Co ntrols.Clear()

PlaceHolder1.Co ntrols.Add(ctl)

End If

MyBase.OnInit(e )

End Sub
End Class


The user control code is :
<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Web UserControl2.as cx.vb" Inherits="fraca s.WebUserContro l2"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:Button id="Button1" Text="Web User Control 2"
runat="server"> </asp:Button>

Public Class WebUserControl2
Inherits System.Web.UI.U serControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

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

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

#End Region

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

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) 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 RaisePostBackEv ent
> > should have been called the control will never find out, whether s.o. clicked
> > on it or not.
> >
> > Try to add the control before "OnPreRende r", 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
1927
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 values from the individual fields in those user controls. So far I am not able to access the controls at postback. Any suggestions would be appreciated. Joel Reinford
1
8190
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 first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
0
1276
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: - Content.ascx has a TabStrip control and a Button on it. - Box.ascx has a PlaceHolder control on it.
0
1425
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 figure out how to fix but there is still no clue. Here is the problem: I define 2 WebUserControls:
1
5261
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. How do I call the following event on UC1 when the sort collumn of the data grid is clicked? Sub DataGrid1_SortCommand(ByVal s As Object, ByVal e As DataGridSortCommandEventArgs)
3
1597
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. I then add the control to the placeholder: Dim myUC As Control = Page.LoadControl("includes/" & ascx_page) myplaceholder.Controls.Add(myUC) Each of these user controls has 2 or 3 textboxes and a Submit button.
1
1161
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 the app. Any ideas or suggestions? Thanks.
5
3083
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 and the specific type of control frequently changes. I have a common event in the base class that each child user control inherits from and that the page wires up and uses to get status from the child user control. I hope all pretty simple and not...
0
1296
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 please help me out? I am using page_init with a IsPostBack condition. but it reloads the user control and I am not able to get the selected values. Thanks in advance. I can provide the code if needed.
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10886
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.