473,811 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LinkButton / doPostBack problem

Hi all,

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

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

Cell.Controls.A dd(deleteRecipi entLink(objRead er("Notificatio nID")))

I feed it with an ID from my database table.

The function 'deleteRecipien tLink' is as follows:

Private Function deleteRecipient Link(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 = "deleteRecipien t" & recipientID
link.CssClass = "normalText "
link.Text = "Delete"
link.ToolTip = "Delete"
link.CausesVali dation = False
link.CommandArg ument = recipientID
link.CommandNam e = "recipientI D"

' 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 3989
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**********@N OSPAMubht.swest .nhs.uk> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi all,

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

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

Cell.Controls.A dd(deleteRecipi entLink(objRead er("Notificatio nID")))

I feed it with an ID from my database table.

The function 'deleteRecipien tLink' is as follows:

Private Function deleteRecipient Link(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 = "deleteRecipien t" & recipientID
link.CssClass = "normalText "
link.Text = "Delete"
link.ToolTip = "Delete"
link.CausesVali dation = False
link.CommandArg ument = recipientID
link.CommandNam e = "recipientI D"

' 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**********@N OSPAMubht.swest .nhs.uk> wrote in message news:eY******** ******@TK2MSFTN GP09.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
1710
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 before clicking in any web server control, as if I'm using the following <A NAME="some_anchor">anchor</a>
3
4113
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 control. If anyone can tell me how to tell .NET to add the doPostBack BEFORE any javascript in the onchange event, it would be most appreciated.
10
2861
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 have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
10
4623
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 = i.ToString(); PageLink.Text = "Page " + i;
4
4224
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 the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
0
4302
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 warning message. I am using datagrid with links as ButtonColumn but I do not want onbeforeunload event called when they are clicked. Any suggestion?
2
5541
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, the system does a "doPostBack" operation. Some of my systems have no issues and work fine. Others fail and time out. I have spoke to the developer at our partners company and he believes that his app is not the culprit. There is no rhyme or reason...
6
14468
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 postback code, but I have a workaround for that installed (and it looks like the code generated by ASP.NET when it renders the page does the same thing, namely, setting document<). However, the problem still exists under firefox. Has anyone come...
2
2718
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 1 2 3 4 5 ... Next Last >> I have achieved the first/previous/next/last buttons quite easily as follows in the ASPX (1.1) page:
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10652
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...
1
10408
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
9211
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
7673
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
6895
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
5561
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
4346
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
3
3026
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.