<% %> tag to get value

  • Thread starter Thread starter Magnus Blomberg
  • Start date Start date
M

Magnus Blomberg

Hello!

I am trying to write a simple aspx page with You are logged on as <% getuser(); %> in the body text.
In my code-behind I write (for test:
public String getuser()
{
String s = Environment.UserDomainName + "\\" + Environment.UserName;
return "testing"; // s;
}

Nothing is returned. Why?!?! What should I do instead?
Regards Magnus
 
What are you doing the the resultant string? ASP.Net is evaluating it properly, but you don't tell it what to do with it. Try instead <% Response.Write(getuser()); %>

You might have better luck though avoiding this older ASP approach. Instead, add an asp.net label control there. Then, in your code behind you can simply set the label's text attribute to the getuser() function and not have any of the issues with trying to have inline calls to code-behind.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

Hello!

I am trying to write a simple aspx page with You are logged on as <% getuser(); %> in the body text.
In my code-behind I write (for test:
public String getuser()
{
String s = Environment.UserDomainName + "\\" + Environment.UserName;
return "testing"; // s;
}

Nothing is returned. Why?!?! What should I do instead?
Regards Magnus
 
Thanks, works just fine by using reponse.write.

I have used .net components for a while but I always have to go via the
page_load event and call a procedure or set the value there.
Do I miss something or is that the recommended way?

Regards Magnus

What are you doing the the resultant string? ASP.Net is evaluating it
properly, but you don't tell it what to do with it. Try instead <%
Response.Write(getuser()); %>

You might have better luck though avoiding this older ASP approach. Instead,
add an asp.net label control there. Then, in your code behind you can simply
set the label's text attribute to the getuser() function and not have any of
the issues with trying to have inline calls to code-behind.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

Hello!

I am trying to write a simple aspx page with You are logged on as <%
getuser(); %> in the body text.
In my code-behind I write (for test:
public String getuser()
{
String s = Environment.UserDomainName + "\\" + Environment.UserName;
return "testing"; // s;
}

Nothing is returned. Why?!?! What should I do instead?
Regards Magnus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top