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

Home Posts Topics Members FAQ

Web Custom Control: getting a updated value on Load event after a postback

Hello.

I wrote a Web Custom Control that have a property named SelectedValue. This SelectedValue property is set after the user clicks a LinkButton control, by its Click() event.

I did some tests, and I noticed that my handled LinkButton_Click() event is fired only after the Page_Load() event, due to page and control lifecicles.

The result of this is, when in Page_Load(), I can only catch the SelectedValue from a previous postback (out of sync).

BUT.... I know and yet did a test with a RadioButtonList. I can retrieve the updated SelectedValue in the Page_Load event with no problem!!

Anyone know the trick so I can update my SelectedValue before the Page_Load() event, soon after the user clicks a LinkButton?

Example (just relevant pieces - better viewed in RichText format):

WebCustomControl:
'retrieves from/sets to viewstate. This property is started with zero ("0")
<DefaultValue(False), Browsable(False)_
Public Property SelectedValue() As Integer
Get
Return CInt(ViewStateClass.Retrieve(ViewState, "SelectedValue", "0"))
End Get
Set(ByVal value As Integer)
ViewStateClass.Save(ViewState, "SelectedValue", CInt(value))
End Set
End Property

'this is where I set the SelectedValue (this event was previously attached via AddHandler)
Private Sub LinkButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
Me.SelectedValue = lnk.CommandArgument
End Sub

Page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = MyControl.SelectedValue '<= on first postback, it returns "0", even
'if the user clicks a LinkButton that returns 20. On second postback, that 20 will
'be returned. Or shortly, it is out of sync.
End Sub

Jun 11 '07 #1
3 1877

"ronchese" <info(a)carsoftnet.com.brwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hello.

I wrote a Web Custom Control that have a property named SelectedValue. This
SelectedValue property is set after the user clicks a LinkButton control, by
its Click() event.

I did some tests, and I noticed that my handled LinkButton_Click() event is
fired only after the Page_Load() event, due to page and control lifecicles.

The result of this is, when in Page_Load(), I can only catch the
SelectedValue from a previous postback (out of sync).

BUT.... I know and yet did a test with a RadioButtonList. I can retrieve the
updated SelectedValue in the Page_Load event with no problem!!

Anyone know the trick so I can update my SelectedValue before the
Page_Load() event, soon after the user clicks a LinkButton?

http://www.15seconds.com/issue/020102.htm

I don't know. Maybe using a Session variable and understanding the ASP.NET
Page Life Cycle and where you can possibly intercept things.
Jun 11 '07 #2
As I understood, even a session variable can itself solve this problem.
It is because the LinkButton_Click() event is raised *after* the Page_Load()
event.

I guess there is a switch or a trick to resolve this.

As MSDN says, Control Events are raised after Page Load:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx
I'm thirsty to find the trick :P


"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:eE**************@TK2MSFTNGP03.phx.gbl...
>
"ronchese" <info(a)carsoftnet.com.brwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hello.

I wrote a Web Custom Control that have a property named SelectedValue.
This SelectedValue property is set after the user clicks a LinkButton
control, by its Click() event.

I did some tests, and I noticed that my handled LinkButton_Click() event
is fired only after the Page_Load() event, due to page and control
lifecicles.

The result of this is, when in Page_Load(), I can only catch the
SelectedValue from a previous postback (out of sync).

BUT.... I know and yet did a test with a RadioButtonList. I can retrieve
the updated SelectedValue in the Page_Load event with no problem!!

Anyone know the trick so I can update my SelectedValue before the
Page_Load() event, soon after the user clicks a LinkButton?

http://www.15seconds.com/issue/020102.htm

I don't know. Maybe using a Session variable and understanding the ASP.NET
Page Life Cycle and where you can possibly intercept things.


Jun 11 '07 #3
Guess I found the trick. It is a workaround, but it works.

http://devsushi.com/2006/09/01/aspne...ntrols-part-2/

[]s
Cesar


"ronchese" <info(a)carsoftnet.com.brwrote in message
news:Ol**************@TK2MSFTNGP05.phx.gbl...
As I understood, even a session variable can itself solve this problem.
It is because the LinkButton_Click() event is raised *after* the
Page_Load() event.

I guess there is a switch or a trick to resolve this.

As MSDN says, Control Events are raised after Page Load:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx
I'm thirsty to find the trick :P


"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:eE**************@TK2MSFTNGP03.phx.gbl...
>>
"ronchese" <info(a)carsoftnet.com.brwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hello.

I wrote a Web Custom Control that have a property named SelectedValue.
This SelectedValue property is set after the user clicks a LinkButton
control, by its Click() event.

I did some tests, and I noticed that my handled LinkButton_Click() event
is fired only after the Page_Load() event, due to page and control
lifecicles.

The result of this is, when in Page_Load(), I can only catch the
SelectedValue from a previous postback (out of sync).

BUT.... I know and yet did a test with a RadioButtonList. I can retrieve
the updated SelectedValue in the Page_Load event with no problem!!

Anyone know the trick so I can update my SelectedValue before the
Page_Load() event, soon after the user clicks a LinkButton?

http://www.15seconds.com/issue/020102.htm

I don't know. Maybe using a Session variable and understanding the
ASP.NET Page Life Cycle and where you can possibly intercept things.



Jun 13 '07 #4

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

Similar topics

2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
0
by: fwirtanen | last post by:
I am building a custom composite control consisting of two drop downs, with parent/child dependancy. The child dropdownlist is updated through client callback when the parent index changes. ...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
0
by: =?Utf-8?B?TWFyayBHaWxrZXM=?= | last post by:
I have designed and written a custom menu like server control. The control inherits from DataBoundControl and implements INamingContainer and IPostBackEventHandler interfaces. The control uses only...
2
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
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
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
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
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,...
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.