Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ASP.Net (VB) DataList Control odd behavior ?

Reply
Thread Tools

ASP.Net (VB) DataList Control odd behavior ?

 
 
AndrewR
Guest
Posts: n/a
 
      09-14-2005
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


 
Reply With Quote
 
 
 
 
AndrewR
Guest
Posts: n/a
 
      09-15-2005
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:etUuX$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Control Odd Behavior AG ASP .Net 5 12-05-2007 06:49 AM
Odd behavior with odd code Michael Speer C Programming 33 02-18-2007 07:31 AM
Odd custom control behavior Wayne Sepega ASP .Net 0 09-05-2006 05:28 PM
ASP.Net (VB) DataList Control odd behavior ? AndrewR ASP .Net 1 09-15-2005 04:37 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM



Advertisments