473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Events for Controls added in code

I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just "reloads"

anybody an idea what I'm missing here?

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click

... add linkbutton to table
End Sub


Nov 19 '05 #1
7 1287
you should manually set its event handler something like this;

LinkButton lb = new LinkButton();
lb.Click+=new EventHandler(lb_click)

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:Oq****************@TK2MSFTNGP14.phx.gbl...
I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just "reloads"

anybody an idea what I'm missing here?

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click

... add linkbutton to table
End Sub

Nov 19 '05 #2
PreRender is too late in the page lifecycle to add events such as click and
change event handlers, as that stage has already passed. You should add these
events sometime in or prior to Page_Load.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just "reloads"
anybody an idea what I'm missing here?

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click
... add linkbutton to table
End Sub


Nov 19 '05 #3
thx
with some gymnastics I can make this work...

is there a place where I can find the order of the events?

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:68**********************@msnews.microsoft.com ...
PreRender is too late in the page lifecycle to add events such as click
and change event handlers, as that stage has already passed. You should
add these events sometime in or prior to Page_Load.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just "reloads"
anybody an idea what I'm missing here?

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click
... add linkbutton to table
End Sub


Nov 19 '05 #4
> is there a place where I can find the order of the events?

The MSDN docs of course have it buired in there somewhere. I've recently
seen a blog post with a graphic of the order. In general they are:

Page and Controls Created
Page_Init
ViewState Loaded
Post data Loaded
Page_Load
Server Side Validation
Any Change Events
Any Click Event
Page_PreRender
Render
Page_Unload
Page is discarded

-Brock
DevelopMentor
http://staff.develop.com/ballen
thx
with some gymnastics I can make this work...

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:68**********************@msnews.microsoft.com ...
PreRender is too late in the page lifecycle to add events such as
click and change event handlers, as that stage has already passed.
You should add these events sometime in or prior to Page_Load.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just
"reloads"
anybody an idea what I'm missing here?
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click
... add linkbutton to table
End Sub


Nov 19 '05 #5
Thanks for the info

but now, if I need to create events depending on a clicked button...
what is the right way to do it then?

this is in fact my case, but for now I worked around it by disable-ing my
buttons

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:68**********************@msnews.microsoft.com ...
is there a place where I can find the order of the events?


The MSDN docs of course have it buired in there somewhere. I've recently
seen a blog post with a graphic of the order. In general they are:

Page and Controls Created
Page_Init
ViewState Loaded
Post data Loaded
Page_Load
Server Side Validation
Any Change Events
Any Click Event
Page_PreRender
Render
Page_Unload
Page is discarded

-Brock
DevelopMentor
http://staff.develop.com/ballen
thx
with some gymnastics I can make this work...

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:68**********************@msnews.microsoft.com ...
PreRender is too late in the page lifecycle to add events such as
click and change event handlers, as that stage has already passed.
You should add these events sometime in or prior to Page_Load.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just
"reloads"
anybody an idea what I'm missing here?
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click
... add linkbutton to table
End Sub


Nov 19 '05 #6
> but now, if I need to create events depending on a clicked button...
what is the right way to do it then?


You dynamically add the control in the button click event, then upon every
postback you need to recreate the controls that were previousally dynamically
created. The trick is how to "remember" on the next postback what you had
previously created. I'd suggest using ViewState. Here's a sample I posted
a while back:

http://groups-beta.google.com/group/...717a97bd32c450

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #7
Dominique Vandensteen wrote:
is there a place where I can find the order of the events?
Dominique, check out these two articles:

Understanding ASP.NET ViewState
http://msdn.microsoft.com/library/de.../viewstate.asp
(see the "The ASP.NET Page Lifecycle" section in particular)

-and-

The ASP.NET Page Object Model
http://msdn.microsoft.com/asp.net/co...bjectmodel.asp

hth


"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:68**********************@msnews.microsoft.com ...
PreRender is too late in the page lifecycle to add events such as click
and change event handlers, as that stage has already passed. You should
add these events sometime in or prior to Page_Load.

-Brock
DevelopMentor
http://staff.develop.com/ballen

I have a Table to which I add a LinkButton in the PreRender event
The LinkButton is visible on the webpage but when I click it,
the LinkButton_Click method is not called and the page just "reloads"
anybody an idea what I'm missing here?

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Dim addRootLink As New LinkButton
AddHandler addRootLink.Click, AddressOf LinkButton_Click
... add linkbutton to table
End Sub



Nov 19 '05 #8

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

Similar topics

3
by: Kenton Smeltzer | last post by:
Hello All, I am having a problem with events and the addition of controls on a page I am developing. First let me tell you what I have tried and then maybe someone can see something I missed. ...
4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
1
by: Paul | last post by:
An early Happy Thanksgiving to you and yours... We develop data driven apps. We dynamically place controls on a panel which may be then be placed on a web form or another control. My problem is...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
0
by: Scott McChesney | last post by:
I have a problem I hope you folks can help me with. I have an application that is using a tab-based interface, with the ability for users to drag an item from a ListBox onto the tab control. ...
18
by: Brett | last post by:
What are reasons to create your own events? Why not just call a class method/function instead? Thanks, Brett
8
by: Xero | last post by:
When my program is launched, there is a textbox on the form. When the user enters a character into the textbox (TextChanged), a second, declared textbox is added using this block of code. Dim...
2
by: =?Utf-8?B?SHV6ZWZh?= | last post by:
Hi, I am using a Multipage control with ASP.Net 1.1. The events for controls within the multipage are not getting fired. Any ideas why this would happen. It was working fine before i added...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.