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

Home Posts Topics Members FAQ

LinkButton / doPostBack problem

Hi all,

I have a bit of code that programmatically adds some table cells/rows to a
table.

The last cell adds a LinkButton control, I call it like this:

Cell.Controls.Add(deleteRecipientLink(objReader("N otificationID")))

I feed it with an ID from my database table.

The function 'deleteRecipientLink' is as follows:

Private Function deleteRecipientLink(ByVal recipientID As Integer) As
LinkButton

' declare variables
Dim link As LinkButton

' create new instance of linkbutton object
link = New LinkButton

' set link properties
link.ID = "deleteRecipient" & recipientID
link.CssClass = "normalText"
link.Text = "Delete"
link.ToolTip = "Delete"
link.CausesValidation = False
link.CommandArgument = recipientID
link.CommandName = "recipientID"

' add handler
AddHandler link.Click, AddressOf deleteRecipient

' return link object

Return (link)

End Function

The problem I'm having is that whilst the link button is not validating my
form (correct), it is obviously doing a post back, which in my case is now
adding more rows to my data (as if the form had been submitted correctly),
what I want to happen is run a different function when the link button is
clicked. I thought adding the AddHandler would have solved this problem but
having stuffed in some breakpoints it never gets to my deleteRecipient
function - it hits the PageIsPostback and then thats it.

What do I need to do? Change my code for the AddHandler some how, or change
my code in the if its a PostBack? if the latter, how do I determine that it
was the linkbutton that did the postback and not the submit button on my
form?

Thanks in advance for any help.

Regards

Rob
Nov 18 '05 #1
3 3964
Controls aren't persisted across postbacks, so if you want that event to fire, you need to recreate the linkbutton just like you did the first time in page_load.

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Hi all,

I have a bit of code that programmatically adds some table cells/rows to a
table.

The last cell adds a LinkButton control, I call it like this:

Cell.Controls.Add(deleteRecipientLink(objReader("N otificationID")))

I feed it with an ID from my database table.

The function 'deleteRecipientLink' is as follows:

Private Function deleteRecipientLink(ByVal recipientID As Integer) As
LinkButton

' declare variables
Dim link As LinkButton

' create new instance of linkbutton object
link = New LinkButton

' set link properties
link.ID = "deleteRecipient" & recipientID
link.CssClass = "normalText"
link.Text = "Delete"
link.ToolTip = "Delete"
link.CausesValidation = False
link.CommandArgument = recipientID
link.CommandName = "recipientID"

' add handler
AddHandler link.Click, AddressOf deleteRecipient

' return link object

Return (link)

End Function

The problem I'm having is that whilst the link button is not validating my
form (correct), it is obviously doing a post back, which in my case is now
adding more rows to my data (as if the form had been submitted correctly),
what I want to happen is run a different function when the link button is
clicked. I thought adding the AddHandler would have solved this problem but
having stuffed in some breakpoints it never gets to my deleteRecipient
function - it hits the PageIsPostback and then thats it.

What do I need to do? Change my code for the AddHandler some how, or change
my code in the if its a PostBack? if the latter, how do I determine that it
was the linkbutton that did the postback and not the submit button on my
form?

Thanks in advance for any help.

Regards

Rob

Nov 18 '05 #2
"Raterus" wrote...
Controls aren't persisted across postbacks, so if you want that event to
fire, you need to recreate the linkbutton just like you did the first time
in page_load.


Hi Raterus,

Thanks for your reply.

A slightly ruder version of "oh crap" just resinated around my office upon
reading your reply :o/

So, where at the moment I run off to my database, get a list of users, and
add the linkbutton control to 'delete' each one, I'd need to run that on the
post back aswell so that the controls exist for the event to then fire?

Correct?

Regards

Rob
Nov 18 '05 #3
That is correct, as much as it's a pain. If you can possibly get the same functionality by using a datagrid/datalist/repeater I'd go that route, as you won't need to do any of this, just handle the event. I remember going through all of this many months ago when I had a similar "delete" problem, after doing what I originally suggested, I then had the problem that I just recreated the very user I wanted to delete. I ended up using a datagrid and all was better.

Hope you can work it out, remember dynamic controls w/ events can be a pain, avoid them if you possibly can!

--Michael

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message news:eY**************@TK2MSFTNGP09.phx.gbl...
"Raterus" wrote...
Controls aren't persisted across postbacks, so if you want that event to
fire, you need to recreate the linkbutton just like you did the first time
in page_load.


Hi Raterus,

Thanks for your reply.

A slightly ruder version of "oh crap" just resinated around my office upon
reading your reply :o/

So, where at the moment I run off to my database, get a list of users, and
add the linkbutton control to 'delete' each one, I'd need to run that on the
post back aswell so that the controls exist for the event to then fire?

Correct?

Regards

Rob

Nov 18 '05 #4

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

Similar topics

0
by: valmir cinquini | last post by:
Hi, I've noticed that a doPostBack call always cause the position of the page goes up to the top of the page, after round trip. I'd like to place the page at original position where it was...
3
by: Mad Scientist Jr | last post by:
I have some javascript I would like to run after a doPostBack occurs: onchange="javascript:__doPostBack('Text1','');" The doPostBack is being added dynamically by .NET when it renders the...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
10
by: Vi | last post by:
Hi, I'm trying to dinamically add LinkButton Controls to a web form. I do something like: for(i=1;i<=someVariable;i++) { LinkButton PageLink = new LinkButton(); PageLink.CommandName =...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
0
by: masoud bayan | last post by:
Hi , I used your suggested code to replace doPostBack in my application, but it seems window.onbeforeunload is called before, window.__doPostBack, so it can not change the condition for showing...
2
by: DSipp | last post by:
First, I am not a developer. My company works with a partner. This partner has a web app that we interact with. All of my systems can connect and login to this site. When we select an issue link,...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
2
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
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
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: 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
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
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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.