473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs)

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

Dim LButton As LinkButton = DirectCast(sender, 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(Session("LastButton")) Then
LButton = DirectCast(Session("LastButton"), LinkButton)
LButton.Enabled = True
End If

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

' Save this button to session variable
Session("LastButton") = 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("LastButton")' 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 2197
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(ByVal sender As System.Object, ByVal e As
System.EventArgs)

.....

' Cast the sender object
LButton = DirectCast(sender, 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.Controls.Count - 1)
DirectCast(LButton.Parent.Parent.Controls.Item(i). Controls.Item(1),
LinkButton).Enabled = 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*************@tk2msftngp13.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(ByVal sender As System.Object, ByVal e As
System.EventArgs)

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

Dim LButton As LinkButton = DirectCast(sender, 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(Session("LastButton")) Then
LButton = DirectCast(Session("LastButton"), LinkButton)
LButton.Enabled = True
End If

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

' Save this button to session variable
Session("LastButton") = 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("LastButton")' 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
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...
4
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...
0
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...
3
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...
6
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...
2
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: ...
0
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...
1
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...
1
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)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
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...
0
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,...

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.