Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some questions about ASP-ASP.NET

Status
Not open for further replies.

gcastillo

Programmer
Jun 9, 2000
127
MX
Hello. I've been developing with ASP and VBS for a while. Now, with ASP.NET I don't know how can I display a value from a simple function. i.e: in ASP I use <%=Date()%> to display the date from the server. How can I do that in .NET? I know I can use the code behind and have the text on a label or something like that, but how can I display the date, or a result from some code behind in the web interfase? I've seen <@, or <#, but they don't do what I wanto... unless, of course, that I'm not using them correctly. Almost everything I do is with code-behind, but sometimes you need to know how to do it both ways ... Thanks for your help.
 
you can do it like this:

myLabel.Text = System.DateTime.Now

-DNG
 
Thanx, DotNetGnat, but that's code behind (in the .vb file). My question would be: If I have in my code a var: myVar = system.datetime.now, or myVar = 23, or myVar="this is only a text", how could I display in the .aspx file, in the HTML interfase, the value for myVar? In ASP I can use: <table><tr><td><%=myVar%></td></tr></table>. How could I do that in .NET? something like <table><tr><td><#=myVar%></td></tr></table>?? or something like <table><tr><td><@myVar%></td></tr></table> maybe?
Thank you in advance
 
i guess you can still use the same syntax...did you try something like this

<asp:textbox id="mytxtbox" text=<%=myvar%> runat=server />

-DNG

 
Nop =( ... This error happens:
"Parser Error Message: Server tags cannot contain <% ... %> constructs"
..... maybe everything needs to be assigned to an element or component in the page?...
 
Have you tried:
string myvar = "test";
Response.Write (myvar);

This should work though:

<td><%=myvar%></td>
 
Thanx, ecannizzo. The response.write works, but you can't specify where the output will be (or, if somebody knows how to do that, please share). And the other option works only if the myVar is declared and the value assigned in the HTML, not in the code behind... =/
 
in order to position your output you need to tie it to a control(a label in this case) and position the label...

-DNG
 
You can assign the variable in the code behind it just has to be public and global ...

in code behind:
public string myvar = string.Empty;
 
You can also use a Literal control and set it's Text property to either plain text or HTML.

I know you are probably a little frustrated by all this, but the whole point is to eliminate the inefficiency of late binding and put the processing into a much more efficient DLL. It’s the kind of stuff that happens when you go from a scripting language to a more advanced compiled language.

I know you can do it by "<%=Now().ToString%>" in ASP.NET 1.1, but it looks like it was eliminated in ASP.NET 2.0.

Senior Software Developer
 
Of course I just got <%=now%> to work in 2.0.

I shut down VS.NET 2005 and the reopened it to show a buddy and it started working. Not sure what that was all about.

Senior Software Developer
 
I think you're rigth, Sirius. The efficiency is bigger in the compiled part... Anyway, the line with <%=Now().ToString%> is exactly what I was looking for.. I just need to know if there's a way to do the same with any variable qith a value assigned in the code behind... Just for the knowledge =)... I'll keep doing all my code in the compiled part. Thanx to everybody!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top