473,597 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net (VB) DataList Control odd behavior ?

Hey all,

Have a strange one here I don't understand....

I have a DataList control in an .aspx page. Inside the DataList's
<ItemTemplate > is a single LinkButton control. On the initial page load-up
I bind the DataList, and set the LinkButton's text and CommandArgument
values to the two items in the result set using the <%# ... %> tags. The
LinkButton's OnClick handler is set to a sub call ShowScores. When the page
is run, I get on screen a nice list of links, and clicking any of them runs
the back side code ShowScores, which was my goal. No problem....but I can't
leave well enough alone.....

I thought that if I could disable the link that was just clicked, it would
make for a better interface...no double clicking the same link, visual cue
as to what was clicked, etc. The sub ShowScores has a signature as follows:

Protected Sub ShowScores(ByVa l sender As System.Object, ByVal e As
System.EventArg s)

To disable the LinkButton control that was clicked, I simply added this in
the sub block:

Dim LButton As LinkButton = DirectCast(send er, LinkButton)
LButton.Enabled = False

Which worked, but when a second link was clicked, the first one was still
disabled. Ok, I thought about it, and came up with the following idea
(replacing the above lines):

Dim LButton As LinkButton

' Re-enable the game button last clicked, if applicable
If Not IsNothing(Sessi on("LastButton" )) Then
LButton = DirectCast(Sess ion("LastButton "), LinkButton)
LButton.Enabled = True
End If

' Disable the game button just clicked
LButton = DirectCast(send er, LinkButton)
LButton.Enabled = False

' Save this button to session variable
Session("LastBu tton") = LButton

This however does not work (sort of). The one just clicked is disabled just
fine, but the previous button remains disabled as well. I set a breakpoint
on the 'LButton = Session("LastBu tton")' line and ran the project. On the
second time around the debugger kicks in. In the Command window I
type"?LButton" I get all the info of the previous button, and the Enabled is
False...which I would figure to be the case. I step a couple lines and get
out of the IF block and type the same line in the Command window again, and
again get the info of the previous button, but now it states the Enable
property is True. I hit F5 and am presented with my quandary....

The previous button is still disabled - despite the fact that I set it True
and the query in the Command window showed it to be set True.

Why is it I can recall the previous button from the Session variable, but it
will not re-enable it? It disabled it just fine. Help?

-- Andrew
Nov 19 '05 #1
1 2217
For those playing the home version, I was able to find a solution to the
problem. I still don't understand why my previous idea didn't work (and not
having received any responses I guess I will have to continue wondering),
but this is what I did to get it to work:

Protected Sub ShowScores(ByVa l sender As System.Object, ByVal e As
System.EventArg s)

.....

' Cast the sender object
LButton = DirectCast(send er, LinkButton)

' From the Button's level, go up to the DataList control
' Parent.Parent because the first Parent is the DataListItem, the
second is the DataList
' Run through the list and enable each button
For i As Int16 = 0 To (LButton.Parent .Parent.Control s.Count - 1)
DirectCast(LBut ton.Parent.Pare nt.Controls.Ite m(i).Controls.I tem(1),
LinkButton).Ena bled = True
Next

' Now disable the button that was clicked
LButton.Enabled = False

.....

End Sub
-- Andrew

"AndrewR" <AndrewR2k1[at]hotmail[dot]com> wrote in message
news:u7******** *****@tk2msftng p13.phx.gbl...
Hey all,

Have a strange one here I don't understand....

I have a DataList control in an .aspx page. Inside the DataList's
<ItemTemplate > is a single LinkButton control. On the initial page
load-up I bind the DataList, and set the LinkButton's text and
CommandArgument values to the two items in the result set using the <%#
... %> tags. The LinkButton's OnClick handler is set to a sub call
ShowScores. When the page is run, I get on screen a nice list of links,
and clicking any of them runs the back side code ShowScores, which was my
goal. No problem....but I can't leave well enough alone.....

I thought that if I could disable the link that was just clicked, it would
make for a better interface...no double clicking the same link, visual cue
as to what was clicked, etc. The sub ShowScores has a signature as
follows:

Protected Sub ShowScores(ByVa l sender As System.Object, ByVal e As
System.EventArg s)

To disable the LinkButton control that was clicked, I simply added this in
the sub block:

Dim LButton As LinkButton = DirectCast(send er, LinkButton)
LButton.Enabled = False

Which worked, but when a second link was clicked, the first one was still
disabled. Ok, I thought about it, and came up with the following idea
(replacing the above lines):

Dim LButton As LinkButton

' Re-enable the game button last clicked, if applicable
If Not IsNothing(Sessi on("LastButton" )) Then
LButton = DirectCast(Sess ion("LastButton "), LinkButton)
LButton.Enabled = True
End If

' Disable the game button just clicked
LButton = DirectCast(send er, LinkButton)
LButton.Enabled = False

' Save this button to session variable
Session("LastBu tton") = LButton

This however does not work (sort of). The one just clicked is disabled
just fine, but the previous button remains disabled as well. I set a
breakpoint on the 'LButton = Session("LastBu tton")' line and ran the
project. On the second time around the debugger kicks in. In the Command
window I type"?LButton" I get all the info of the previous button, and the
Enabled is False...which I would figure to be the case. I step a couple
lines and get out of the IF block and type the same line in the Command
window again, and again get the info of the previous button, but now it
states the Enable property is True. I hit F5 and am presented with my
quandary....

The previous button is still disabled - despite the fact that I set it
True and the query in the Command window showed it to be set True.

Why is it I can recall the previous button from the Session variable, but
it will not re-enable it? It disabled it just fine. Help?

-- Andrew

Nov 19 '05 #2

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

Similar topics

10
2835
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...
4
6544
by: krzysiek | last post by:
hello, i have several radiolists and checkboxlist that are generated dinamicly based on datasource. So frankly speaking i don't know names and number of that web controls cose they are always different. How can i retreive selected values from those controls ?
0
1401
by: vbMental | last post by:
I'm almost certain this is a bug, or atleast "undesirable behavior". I felt the checkbox list control had shortcomings so I ventured on creating my own checkbox list user control. To put it shortly, the usercontrol had a checkbox list inside of it, that would be bound by a datasource that was to be specified as a property of the control. It also had an all checkbox at the top that would select all of the checkboxes in the list... The...
3
5935
by: David Hearn | last post by:
I have a datalist that I have inserted a radio button into. The datalist populates with a list of items and each one has a radio button next to it. I need to use the radio button to allow the user to select a default item so when the user clicks one of the radio buttons, it needs to clear the checked property from the rest. This is default behavior for the radio button, but it doesn't work when it is embedded into a datalist. I have tried...
6
2181
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label on the footer. At the moment, I go through the dataListItems like so: for each oItem as DataListItem in DataList1.Items trace.warn("inside for loop oItem type = " & oItem.itemType.ToString())
2
3431
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: //Page_load of my user control protected void Page_Load(object sender, EventArgs e) { IDataItemContainer DataContainer = this.Parent as
0
3931
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a strogly typed collection I called TabCollection which is a collevtion of items called tab. Each tab is as follows:
1
4317
by: sck10 | last post by:
Hello, I have created a photo gallery of thumbnails using the code below. So far, I got the pictures to show, but now I need to figure out how a viewer can click on the thumbnail and it opens the bigger picture. The bigger file is the same name as the file stored in the array minus the "_mini". So in the datalist, I would need to somehow wrap the image inside of the anchor. Any help with this would be appreciated. Thanks in advance ...
1
2021
by: berny.zamora | last post by:
Hello everyone, I have a composite control (lets call it the parent) that contains a datalist. The datalist has an ItemTemplate that contains another composite control (lets call it the child). I am trying to create a property at the parent control that sets a property in the child instances. So for example lets say I am creating a control that displays a list of hotel reservations for a group of people.
0
7885
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
8271
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
8031
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
8258
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
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
3881
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
2399
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
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1231
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.