Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How can I do this?

Reply
Thread Tools

How can I do this?

 
 
m.a
Guest
Posts: n/a
 
      09-15-2008
Thanks, it is working but what if I want to use it with an asp control? for
example, if I want to hide/show a control based on some calculation?

for example I may want to do:

<asp:Label runat="server" ID="test" Text='test' visible=<%# ShouldShow()%>'
/>



Regards



"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have code like this. But I didn't use a label control. I just did
>something like this:
>
> <% GetAString(); %>
>
> It works for me.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "m.a" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> It is not working since the function never called.
>>
>> "Jonathan Wood" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>> protected string GetAString()
>>>> {
>>>> return "test";
>>>> }
>>>
>>> Try this instead:
>>>
>>> protected void GetAString()
>>> {
>>> Response.Write("test");
>>> }
>>>
>>> --
>>> Jonathan Wood
>>> SoftCircuits Programming
>>> http://www.softcircuits.com
>>>
>>> "m.a" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>
>>>> "Hans Kesting" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> m.a explained on 15-9-2008 :
>>>>>> Hello,
>>>>>>
>>>>>> I know that I can do this:
>>>>>>
>>>>>> <asp:Label runat="server" ID="test" text='<%# Eval("a_field")%>'
>>>>>> ></asp:Label>
>>>>>>
>>>>>>
>>>>>>
>>>>>> but how can I do this:
>>>>>>
>>>>>> <asp:Label runat="server" ID="test" text='<%# GetAString()%>'
>>>>>> ></asp:Label>
>>>>>>
>>>>>>
>>>>>>
>>>>>> where GetAString() is a C# function returning a string (sample as
>>>>>> follow):
>>>>>>
>>>>>>
>>>>>>
>>>>>> public static string GetSString()
>>>>>>
>>>>>> {
>>>>>>
>>>>>> return "test";
>>>>>>
>>>>>> }
>>>>>>
>>>>>> when I add the above line to my aspx page, I am not getting any
>>>>>> error, but nothing for label is shown when it should show test.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Any suggestion on what is the problem?
>>>>>>
>>>>>> Regards
>>>>>
>>>>> <asp:Label runat="server" ID="test" text='<%= GetAString()%>' />
>>>>>
>>>>> use "%=" instead of "%#"
>>>>>
>>>>> Hans Kesting
>>>>>
>>>>>
>>>>
>>>> Thanks, but it doesn't work.
>>>>
>>>> I created a new project in MSVS2008 and the default.aspx is :
>>>>
>>>>
>>>>
>>>> <%@ Page Language="C#" AutoEventWireup="true"
>>>> CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
>>>>
>>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>>>
>>>> <html xmlns="http://www.w3.org/1999/xhtml" >
>>>>
>>>> <head runat="server">
>>>>
>>>> <title></title>
>>>>
>>>> </head>
>>>>
>>>> <body>
>>>>
>>>> <form id="form1" runat="server">
>>>>
>>>> <div>
>>>>
>>>> <asp:Label runat="server" ID="test" text='<%= GetAString()%>' />
>>>>
>>>> </div>
>>>>
>>>> </form>
>>>>
>>>> </body>
>>>>
>>>> </html>
>>>>
>>>>
>>>>
>>>> And the default.aspx.cs is as follow:
>>>>
>>>>
>>>>
>>>> using System;
>>>>
>>>> using System.Collections.Generic;
>>>>
>>>> using System.Linq;
>>>>
>>>> using System.Web;
>>>>
>>>> using System.Web.UI;
>>>>
>>>> using System.Web.UI.WebControls;
>>>>
>>>> namespace WebApplication1
>>>>
>>>> {
>>>>
>>>> public partial class _Default : System.Web.UI.Page
>>>>
>>>> {
>>>>
>>>> protected void Page_Load(object sender, EventArgs e)
>>>>
>>>> {
>>>>
>>>> }
>>>>
>>>>
>>>> }
>>>>
>>>> but when I run the application, the result is a blank page.
>>>>
>>>> any suggestion?
>>>>
>>>> Regards
>>>>
>>>>
>>>>
>>>>
>>>

>>
>>

>



 
Reply With Quote
 
 
 
 
Jonathan Wood
Guest
Posts: n/a
 
      09-15-2008
Not sure. For me, I'd simply write a little code in the Load event and set
the visibility there.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"m.a" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Thanks, it is working but what if I want to use it with an asp control?
> for example, if I want to hide/show a control based on some calculation?
>
> for example I may want to do:
>
> <asp:Label runat="server" ID="test" Text='test' visible=<%#
> ShouldShow()%>' />
>
>
>
> Regards
>
>
>
> "Jonathan Wood" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have code like this. But I didn't use a label control. I just did
>>something like this:
>>
>> <% GetAString(); %>
>>
>> It works for me.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>> "m.a" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> It is not working since the function never called.
>>>
>>> "Jonathan Wood" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>> protected string GetAString()
>>>>> {
>>>>> return "test";
>>>>> }
>>>>
>>>> Try this instead:
>>>>
>>>> protected void GetAString()
>>>> {
>>>> Response.Write("test");
>>>> }
>>>>
>>>> --
>>>> Jonathan Wood
>>>> SoftCircuits Programming
>>>> http://www.softcircuits.com
>>>>
>>>> "m.a" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>>
>>>>> "Hans Kesting" <(E-Mail Removed)> wrote in message
>>>>> news:(E-Mail Removed)...
>>>>>> m.a explained on 15-9-2008 :
>>>>>>> Hello,
>>>>>>>
>>>>>>> I know that I can do this:
>>>>>>>
>>>>>>> <asp:Label runat="server" ID="test" text='<%# Eval("a_field")%>'
>>>>>>> ></asp:Label>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> but how can I do this:
>>>>>>>
>>>>>>> <asp:Label runat="server" ID="test" text='<%# GetAString()%>'
>>>>>>> ></asp:Label>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> where GetAString() is a C# function returning a string (sample as
>>>>>>> follow):
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> public static string GetSString()
>>>>>>>
>>>>>>> {
>>>>>>>
>>>>>>> return "test";
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> when I add the above line to my aspx page, I am not getting any
>>>>>>> error, but nothing for label is shown when it should show test.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Any suggestion on what is the problem?
>>>>>>>
>>>>>>> Regards
>>>>>>
>>>>>> <asp:Label runat="server" ID="test" text='<%= GetAString()%>' />
>>>>>>
>>>>>> use "%=" instead of "%#"
>>>>>>
>>>>>> Hans Kesting
>>>>>>
>>>>>>
>>>>>
>>>>> Thanks, but it doesn't work.
>>>>>
>>>>> I created a new project in MSVS2008 and the default.aspx is :
>>>>>
>>>>>
>>>>>
>>>>> <%@ Page Language="C#" AutoEventWireup="true"
>>>>> CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
>>>>>
>>>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>>>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>>>>
>>>>> <html xmlns="http://www.w3.org/1999/xhtml" >
>>>>>
>>>>> <head runat="server">
>>>>>
>>>>> <title></title>
>>>>>
>>>>> </head>
>>>>>
>>>>> <body>
>>>>>
>>>>> <form id="form1" runat="server">
>>>>>
>>>>> <div>
>>>>>
>>>>> <asp:Label runat="server" ID="test" text='<%= GetAString()%>' />
>>>>>
>>>>> </div>
>>>>>
>>>>> </form>
>>>>>
>>>>> </body>
>>>>>
>>>>> </html>
>>>>>
>>>>>
>>>>>
>>>>> And the default.aspx.cs is as follow:
>>>>>
>>>>>
>>>>>
>>>>> using System;
>>>>>
>>>>> using System.Collections.Generic;
>>>>>
>>>>> using System.Linq;
>>>>>
>>>>> using System.Web;
>>>>>
>>>>> using System.Web.UI;
>>>>>
>>>>> using System.Web.UI.WebControls;
>>>>>
>>>>> namespace WebApplication1
>>>>>
>>>>> {
>>>>>
>>>>> public partial class _Default : System.Web.UI.Page
>>>>>
>>>>> {
>>>>>
>>>>> protected void Page_Load(object sender, EventArgs e)
>>>>>
>>>>> {
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>> but when I run the application, the result is a blank page.
>>>>>
>>>>> any suggestion?
>>>>>
>>>>> Regards
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
 
m.a
Guest
Posts: n/a
 
      09-15-2008
No I am not getting any error.
Whatr is the difference between
<%= %> and <%# %> ?

where can I read more about this?

Regards



"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "m.a" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>>> protected string GetAString()
>>>
>>> Are you sure that your code-behind function is being called? Put a
>>> breakpoint in it to check...

>>
>> No it is not called?

>
> Well, there's the problem!
>
>> But I don't know why? What is wrong in my code?

>
> Difficult to tell immediately...
>
> If you do this:
>
> <asp:Label runat="server" ID="test" text='<%= zzzzGetAString()%>' />
>
> do you get a runtime error...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
Word Docs Won't Open, Can't Be E-Mailed, Can't Be Deleted, Can't Be Copied, Etc. Martin Computer Support 16 02-24-2009 07:35 PM
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM



Advertisments