471,354 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 2098
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bharat | last post: by
4 posts views Thread by krzysiek | last post: by
6 posts views Thread by tshad | last post: by

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.