473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I do this?

m.a

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


Sep 15 '08 #1
16 1042
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
Sep 15 '08 #2
m.a

"Hans Kesting" <ne*********@sp amgourmet.comwr ote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
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="Def ault.aspx.cs"
Inherits="WebAp plication1._Def ault" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<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.Collecti ons.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

namespace WebApplication1

{

public partial class _Default : System.Web.UI.P age

{

protected void Page_Load(objec t sender, EventArgs e)

{

}

protected string GetAString()

{

return "test";

}

}

but when I run the application, the result is a blank page.

any suggestion?

Regards


Sep 15 '08 #3
for a data binding expression to be evaluated, you still need to call
DataBind().

-- bruce (sqlwork.com)
"m.a" wrote:
>
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


Sep 15 '08 #4
m.a
Thanks,
But it is not a databinding expression. I also add the databind() to the
form_load but no difference, (with the refrence to the codes that I send
with my second post.

Regards

"bruce barker" <br*********@di scussions.micro soft.comwrote in message
news:BB******** *************** ***********@mic rosoft.com...
for a data binding expression to be evaluated, you still need to call
DataBind().

-- bruce (sqlwork.com)
"m.a" wrote:
>>
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



Sep 15 '08 #5
"m.a" <ma.@spamoff.co mwrote in message
news:u2******** *****@TK2MSFTNG P05.phx.gbl...
>><asp:Label runat="server" ID="test" text='<%# GetAString()%>'
></asp:Label>

<asp:Label runat="server" ID="test" text='<%= GetAString()%>' />

use "%=" instead of "%#"

Thanks, but it doesn't work.

I created a new project in MSVS2008 and the default.aspx is :

protected string GetAString()
Are you sure that your code-behind function is being called? Put a
breakpoint in it to check...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 15 '08 #6
m.a

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:e5******** ******@TK2MSFTN GP05.phx.gbl...
"m.a" <ma.@spamoff.co mwrote in message
news:u2******** *****@TK2MSFTNG P05.phx.gbl...
>>><asp:Label runat="server" ID="test" text='<%# GetAString()%>'
></asp:Label>
<asp:Label runat="server" ID="test" text='<%= GetAString()%>' />

use "%=" instead of "%#"

Thanks, but it doesn't work.

I created a new project in MSVS2008 and the default.aspx is :

protected string GetAString()

Are you sure that your code-behind function is being called? Put a
breakpoint in it to check...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
No it is not called? But I don't know why? What is wrong in my code?


Sep 15 '08 #7
protected string GetAString()
{
return "test";
}
Try this instead:

protected void GetAString()
{
Response.Write( "test");
}

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

"m.a" <ma.@spamoff.co mwrote in message
news:u2******** *****@TK2MSFTNG P05.phx.gbl...
>
"Hans Kesting" <ne*********@sp amgourmet.comwr ote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
>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="Def ault.aspx.cs"
Inherits="WebAp plication1._Def ault" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<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.Collecti ons.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

namespace WebApplication1

{

public partial class _Default : System.Web.UI.P age

{

protected void Page_Load(objec t sender, EventArgs e)

{

}
}

but when I run the application, the result is a blank page.

any suggestion?

Regards

Sep 15 '08 #8
m.a
It is not working since the function never called.

"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Or******** *****@TK2MSFTNG P05.phx.gbl...
>protected string GetAString()
{
return "test";
}

Try this instead:

protected void GetAString()
{
Response.Write( "test");
}

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

"m.a" <ma.@spamoff.co mwrote in message
news:u2******** *****@TK2MSFTNG P05.phx.gbl...
>>
"Hans Kesting" <ne*********@sp amgourmet.comwr ote in message
news:uR******* *******@TK2MSFT NGP05.phx.gbl.. .
>>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="De fault.aspx.cs" Inherits="WebAp plication1._Def ault" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<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.Collecti ons.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

namespace WebApplication1

{

public partial class _Default : System.Web.UI.P age

{

protected void Page_Load(objec t sender, EventArgs e)

{

}
}

but when I run the application, the result is a blank page.

any suggestion?

Regards


Sep 15 '08 #9
but it is a databinding expression, even it if does not access the databound
object. call DataBind() on the label, when you wnat the evaluation to take
effect.

Databinding expressions are pretty simple, when the page is compiled, if a
control has a databinding expression (property = "<%# expr() %>") then the
equalivent to following code is generated (actually ondatabinding fires an
event to call a delegate, instead of calling the code direct) :

OnDataBinding(E vaneArg e)
{
property = expr();
}

-- bruce (sqlwork.com)
"m.a" wrote:
Thanks,
But it is not a databinding expression. I also add the databind() to the
form_load but no difference, (with the refrence to the codes that I send
with my second post.

Regards

"bruce barker" <br*********@di scussions.micro soft.comwrote in message
news:BB******** *************** ***********@mic rosoft.com...
for a data binding expression to be evaluated, you still need to call
DataBind().

-- bruce (sqlwork.com)
"m.a" wrote:
>
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




Sep 15 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3363
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company Order By Company ASC";
5
2757
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to $location_other I keep getting "Notice: Undefined index: location_other" referring to (!($_POST)) { $location_other = $location; } else
2
2734
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form page************************************************************ <form action="/process.php" method="get" name="formOne" id="formOne"> <select name="owner" size="6" multiple id="owner"> <option value="one">one</option> <option...
2
2556
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") || ($x=="two") || ... || ($x=="seven")) ... or 2) switch ($x){ case("one"):
0
3284
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records each!!!) Dan ==================== <style> body, table, tr, td { font-family: 'verdana'; font-size: 12px;
5
3233
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
10057
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function func1()
6
2670
by: Phil Powell | last post by:
Ok guys, here we go again! SELECT s.nnet_produkt_storrelse_navn FROM nnet_produkt_storrelse s, nnet_produkt_varegruppe v, nnet_storrelse_varegruppe_assoc sv, nnet_produkt p WHERE s.nnet_produkt_storrelse.id = sv.nnet_produkt_storrelse_id AND sv.nnet_produkt_varegruppe_id = v.nnet_produkt_varegruppe_id AND sv.nnet_produkt_varegruppe_id IN ( SELECT nnet_produkt_varegruppe_id FROM nnet_produkt_varegruppe
1
2198
by: Michel | last post by:
a site like this http://www.dvdzone2.com/dvd Can you make it in PHP and MySQL within 6 weeks? If so, send me your price 2 a r a (at) p a n d o r a . b e
11
3186
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in /home/krecik/public_html/silnik.php on line 251 Line 208: print ( "error: " . mysql_error()); Line 251: session_register("uprawnienia", "zalogowany"); I can understand that sth, is wrong in line 251 after line 208 and it is logical to
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.