Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I recently started converting code from VB to C# and stumbled upon something. On VB.NET on the aspx page I can easily do an evaluation of session and eval values like this ...

ASP.NET
<asp:ImageButton CssClass="images" ID="btnDelete" runat="server" ToolTip="Remove" Visible='<%# Session("Role") = 3 And Eval("IsClosed") = False And Eval("Deleted") = False%>'/>


I can use a complex embedded expression to control the visible property using VB, but I can seem to find a way to do it on C#.

Is there a way of easily doing this on C#
Posted
Updated 26-Sep-14 12:47pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Sep-14 18:16pm    
Not quite clear. Perhaps you need to start with what do you want to achieve.
—SA
nfiguer 29-Sep-14 8:54am    
Hi Sergey

What I am trying to achieve is quite simple. In this case (see code above) I am trying to set the button visible property taking into account a few conditions. In VB.NET I simply embed this code in the visible property aspx code. Not able to do that in C#, which is a bummer since it appears that VB ends up being more powerful at this than C#
Sergey Alexandrovich Kryukov 29-Sep-14 10:12am    
Functionally, C# and VB.NET are just .NET languages. You can automatically translate one into another.
—SA
nfiguer 29-Sep-14 14:08pm    
Sergey

I didn't my as a whole but in this particular situation. In any case, Richard posted a solution that pointed out the error with his solution, I simply forgot to establish the preceding datatype for each object. A C# amateur's error. My apologies!

nfiguer wrote:

Hi Sergey

What I am trying to achieve is quite simple. In this case (see code above) I am trying to set the button visible property taking into account a few conditions. In VB.NET I simply embed this code in the visible property aspx code. Not able to do that in C#, which is a bummer since it appears that VB ends up being more powerful at this than C#
I don't remember VB (whatever it is) being more powerful than C# (the opposite certainly happen); this is rather a matter of your taste.

But the languages are just the .NET languages and are kept close to each other functionally. They are close enough to be automatically and cleanly translated one into another. Please see my past answers:
Code Interpretation, C# to VB.NET[^],
Need to convert vb code to c#[^].

—SA
 
Share this answer
 
C# has exactly the same functionality available - you just need to convert the expression to C#, and insert the required type-casts:
ASP.NET
<asp:ImageButton CssClass="images" ID="btnDelete" runat="server" ToolTip="Remove" Visible='<%# (int)Session["Role"] == 3 && (bool)Eval("IsClosed") == false && (bool)Eval("Deleted") == false %>'/>

NB: This syntax only works within a data-bound control. The same limitation applies regardless of the code's language.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Sep-14 14:54pm    
5ed.
—SA
Try a C# Webservice to invoke some C# code on a server to have enough computation power.
Here is a link to a guide for C# Web Service.

Why dont you use javascript?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900