0

Hello There I'm trying to set the visibility of button in list view item template based on the session object and databound property

<asp:Button ID="deleteCommentButton" runat="server" Text="Delete Comment"
            CssClass="redButton" 
            ToolTip="<%# Session[1].ToString() %>" 
            Visible="<%# Session[1].ToString() == Bind("fullname") ? true : false %>"
            style="float:right; margin-left:5px; margin-top:-25px;"
            onclick="deleteCommentButton_Click" />

But I'm getting errors . . Any suggestions?

Tim
  • 28,212
  • 8
  • 63
  • 76
Muhammad Usman
  • 163
  • 1
  • 4
  • 20
  • What error(s) are you getting? – Tim Oct 23 '11 at 20:29
  • Parser Error Message: The server tag is not well formed. Please HELP .. – Muhammad Usman Oct 23 '11 at 20:48
  • I don't believe you can set the Tooltip property by databinding. – Tim Oct 23 '11 at 20:51
  • When I change the code of visible to this Visible="<%# Session[1].ToString() == Bind('fullname') ? true : false %>" I get this Compiler Error Message: CS1012: Too many characters in character literal – Muhammad Usman Oct 23 '11 at 20:52
  • Nada the tool tip property is just working fine . . Im using it in my other controls too. I think the error is when i set visible property to above mentioned conditional logic – Muhammad Usman Oct 23 '11 at 20:54
  • Can you suggest me some other way to display this delete button only for that user : when he sees his post in list view AND is online ? – Muhammad Usman Oct 23 '11 at 20:57
  • Have you tried Visible='<%# Session[1].ToString() == Bind("fullname") ? true : false %>'? Note the single quotes instead of the double quotes. – Tim Oct 23 '11 at 21:00
  • Yes when i use double quotes it gives me the parse error that server tag is not well formed ? – Muhammad Usman Oct 23 '11 at 21:03
  • I'm suggesting to try using single quotes instead of double quotes. – Tim Oct 23 '11 at 21:04
  • Whenn i use single quotes it states that there are too many characters in the character literal? I have googled this error and found that this error occurs when you use single quotes where you should have used double quotes! – Muhammad Usman Oct 23 '11 at 21:06
  • Please help is there any work around for this? – Muhammad Usman Oct 23 '11 at 21:09

1 Answers1

0

Please try this

<asp:Button ID="deleteCommentButton" runat="server" Text="Delete Comment"
        CssClass="redButton" 
        ToolTip='<%# HttpContext.Current.Session[1].ToString() %>' 
        Visible='<%# HttpContext.Current.Session[1].ToString() == Bind("fullname") ? true : false %>'
        style="float:right; margin-left:5px; margin-top:-25px;"
        onclick="deleteCommentButton_Click" />
a7mad.3ezz
  • 101
  • 1
  • 6
  • Heya thanks for posting! But this doesnt work. Gives me the error that Bind does not exists in current context. But when i change Bind with Eval it works!! But not the way i wanted. I.e when i have the same name in session and in databound field it should display the button for that case and hide it for the other. It is hiding for all the list even though the condition to show the button is true? – Muhammad Usman Oct 23 '11 at 21:24
  • OHHHHHH Thanks for leading me so close to solution. I reckon the thing was that it was not comparing the two strings but their reference. Changing the equals signs with the .Equal function did the trick. a7mad.3ezz Thanks for saving my day – Muhammad Usman Oct 23 '11 at 21:31
  • lol glad i did help, although i missed the Bind() and Eval() thingy and the string comparison .. but there you go :) – a7mad.3ezz Oct 23 '11 at 21:35
  • Heyy man im now getting this exception System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index I think its because i have used Eval() ??? – Muhammad Usman Oct 23 '11 at 21:40
  • This thing is getting evil .. can you find out whats the problem here ? Everything did work perfectly before . . Is it because i used eval instead of bind to bound data? How can i use bind function ? – Muhammad Usman Oct 23 '11 at 21:41
  • Is there an element at Session[1]? I.e., do you have at least 2 items in your Session object? – Tim Oct 24 '11 at 00:12