473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET (Visual Studio 2005, .NET 2.0): AddHandler ..., AddressOf ...: order of execution problem

Hi:

I was wondering if anybody had a similar problem and could help me out
with a situation I ran into. I would really appreciate any advice.

I've created an .aspx page for my Web Application in Visual Studio
2005. I'm using .NET version 2.0. The situation narrows down to the
following:

-- I have a Private Sub FillTable(ByVal parameter As String) that
programmatically generates as many <tr>...</tr(TableRows) as there
are records in my database and adds them to a placeholder
(placeholder.controls.add(TableRow)).

-- Inside of the FilLTable subroutine amoung all other stuff I
generate
LinkButtons (one per record) like so:
Dim btnMyLinkButton As LinkButton
btnMyLinkButton = New LinkButton
btnMyLinkButton.Text = [getting a value from my
database]
btnMyLinkButton.ID = [first part of the ID] & "!"
& [second part of the ID] 'this is to be used
later
AddHandler btnMyLinkButton.Click, AddressOf
btnMyLinkButton_Click
...

-- Somewhere below the FillTable subroutine I have another sub:
Private Sub btnMyLinkButton_Click(ByVal s As Object, ByVal e
As System.EventArgs)
Dim B As LinkButton = DirectCast(s, LinkButton)
Dim ItemInfo() As String = B.ID.Split("!"c)

Dim OrderNumber As Int32 = Convert.ToInt32(ItemInfo(0))
Dim LineNumber As Int32 = Convert.ToInt32(ItemInfo(1))
Me.ViewState("PartNumber") = Nothing
AddPart(LineNumber, OrderNumber)
txtPartLookupControl.Text = String.Empty
End Sub

-- When I'm running my project, the link buttons are created normally,
but the onclick event does not catch btnMyLinkButton_Click, but is a
regular PostBack. That is, when a link button is clicked, the page
refreshes whithout even running btnMyLinkButton_Click sub. It looks
like AddHandler...AddressOf... is trying to get the sub, but doesn't
find it (probably because the sub isn't built yet or something like
that). I've tried to place btnMyLinkButton_Click() sub above
FillTable(), but that was silly anyway and sure didn't help.

Any suggestion would be highly appreciated.
Thank you very much for your time!

Jun 21 '07 #1
3 1883
on postback you have to call the filltable routine (or the postback
class instance will not have the controls nor the handler hookups). this
should be done in oninit. also you should not use "!" in and id as its
not legal char.
-- bruce (sqlwork.com)


Vassili King wrote:
Hi:

I was wondering if anybody had a similar problem and could help me out
with a situation I ran into. I would really appreciate any advice.

I've created an .aspx page for my Web Application in Visual Studio
2005. I'm using .NET version 2.0. The situation narrows down to the
following:

-- I have a Private Sub FillTable(ByVal parameter As String) that
programmatically generates as many <tr>...</tr(TableRows) as there
are records in my database and adds them to a placeholder
(placeholder.controls.add(TableRow)).

-- Inside of the FilLTable subroutine amoung all other stuff I
generate
LinkButtons (one per record) like so:
Dim btnMyLinkButton As LinkButton
btnMyLinkButton = New LinkButton
btnMyLinkButton.Text = [getting a value from my
database]
btnMyLinkButton.ID = [first part of the ID] & "!"
& [second part of the ID] 'this is to be used
later
AddHandler btnMyLinkButton.Click, AddressOf
btnMyLinkButton_Click
...

-- Somewhere below the FillTable subroutine I have another sub:
Private Sub btnMyLinkButton_Click(ByVal s As Object, ByVal e
As System.EventArgs)
Dim B As LinkButton = DirectCast(s, LinkButton)
Dim ItemInfo() As String = B.ID.Split("!"c)

Dim OrderNumber As Int32 = Convert.ToInt32(ItemInfo(0))
Dim LineNumber As Int32 = Convert.ToInt32(ItemInfo(1))
Me.ViewState("PartNumber") = Nothing
AddPart(LineNumber, OrderNumber)
txtPartLookupControl.Text = String.Empty
End Sub

-- When I'm running my project, the link buttons are created normally,
but the onclick event does not catch btnMyLinkButton_Click, but is a
regular PostBack. That is, when a link button is clicked, the page
refreshes whithout even running btnMyLinkButton_Click sub. It looks
like AddHandler...AddressOf... is trying to get the sub, but doesn't
find it (probably because the sub isn't built yet or something like
that). I've tried to place btnMyLinkButton_Click() sub above
FillTable(), but that was silly anyway and sure didn't help.

Any suggestion would be highly appreciated.
Thank you very much for your time!
Jun 21 '07 #2
Bruce,

Thank you for your response. A small problem with this approach would
be passing a parameter that is entered in a text box on the same page.
It is not a hard thing to solve though (capture it in a hidden field,
viewstate or similar stuff).

Actually, I've just found another solution:

I've created a hidden field with ID="hfLinkButton". Inside of the
FilLTable subroutine I have btnInvoice.OnClientClick =
"document.forms.aspnetForm._ctl0_ContentPlaceHolde r1_hfLinkButton.value='"
& [first part of the ID] & "!" & [second part of the ID] & "';"

Page_Load catches the value of the hidden field and when it is <0,
sends the value to the modified btnMyLinkButton_Click() sub like so:

Dim strLinkButtonValue As String = hfLinkButton.Value
If strLinkButtonValue <"" Then
btnMyLinkButton_Click(strLinkButtonValue)
End If

That's it.
Thank you very much for your time.

Jun 21 '07 #3
P.S. And I've changed the "!" :)
Thanks!

Jun 21 '07 #4

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

Similar topics

1
986
by: Ola Johansson | last post by:
I have made a custom "Pagebase" class that i inherits from all my web form pages. In my InitializeComponent method on each page i have added a "AddHandler Me.Load, AddressOf Page_Load". The...
9
2791
by: String | last post by:
Don't have the fix I need it. This is the exact problem from microsoft: http://support.microsoft.com/default.aspx?scid=kb;en-us;819349 They do a nice job describing it and how to reproduce it....
4
2362
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances...
7
1773
by: Phill Emery | last post by:
hi can anyone please help me? Im new to visual studio 2003 and im trying to create a program in visual basic. The problem is i have put a menu bar onto the first form, and have created some...
6
3044
by: Rich | last post by:
Hello, I have an application that contains several checkboxes. I originally created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I understand the vb2005 supports control...
5
2194
by: Slim | last post by:
i have a simple page, with one button button1. when click it creates a new button button 2 and adds a event handler to it. but when button 2 is clicked nothing happens, why? Partial Class...
16
4894
by: Omar Abid | last post by:
Hi every body, Im using VB 2005 to create a program that open SQL Data base The problem that i want to detect the tables of a database so how can i know a data base tables instantly Thank you...
1
2858
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
0
7295
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
0
7218
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
7103
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
7478
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
5035
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
4701
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...
0
3188
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
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.