473,659 Members | 2,722 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
programmaticall y generates as many <tr>...</tr(TableRows) as there
are records in my database and adds them to a placeholder
(placeholder.co ntrols.add(Tabl eRow)).

-- 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.EventArg s)
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("P artNumber") = Nothing
AddPart(LineNum ber, OrderNumber)
txtPartLookupCo ntrol.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...Ad dressOf... 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 1886
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
programmaticall y generates as many <tr>...</tr(TableRows) as there
are records in my database and adds them to a placeholder
(placeholder.co ntrols.add(Tabl eRow)).

-- 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.EventArg s)
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("P artNumber") = Nothing
AddPart(LineNum ber, OrderNumber)
txtPartLookupCo ntrol.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...Ad dressOf... 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="hfLinkButto n". Inside of the
FilLTable subroutine I have btnInvoice.OnCl ientClick =
"document.forms .aspnetForm._ct l0_ContentPlace Holder1_hfLinkB utton.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 strLinkButtonVa lue As String = hfLinkButton.Va lue
If strLinkButtonVa lue <"" Then
btnMyLinkButton _Click(strLinkB uttonValue)
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
993
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 problem is that each time i view my page in the designer VS.net removes my "AddHandler Me.Load, AddressOf Page_Load". And add "Handles MyBase.Load" on the "Page_Load" method.
9
2794
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. They say "yes its a bug". How do I fix it? Any ideas? Thanks
4
2366
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 that the test proctor who is viewing the page has currently assigned to him or heir. Each row of the table corresponds to a single test instance and includes required info about that test. At the end of the row I create a button control. Based on...
7
1782
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 other forms but cannot find any options to point from the menu to any of the other forms i have created. can anyone help me, as i would be very greatful
6
3054
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 arrays. Is this correct? If so, I would like to convert my checkboxes to a control array, but without having to recreate them from scratch because their placement was a real pain. Is it possible to go to the property sheet of each checkbox and assign...
5
2202
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 test_buttons Inherits System.Web.UI.Page Dim bt2 As Button
16
4909
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 omar.abid@hotmail.com omar.abid2006@gmail.com Omar abid
1
2883
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 file which includes some html code to populate html formatted content as the text of an asp:label (<asp:label>). The reading of the text file itself goes just fine ;however, this only occurs when I use an absolute file path which will not work of...
0
7324
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 beginning CIS student who is struggling to get their programs working. I work in the computer lab at the college I'm attending and I see many students who don't know how to use the IDE for best results. Visual Studio automatically creates a number of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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
8525
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
7356
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...
1
6179
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
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 we have to send another system
2
1975
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.