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!

Getting c# variable into HTML 4

Status
Not open for further replies.

columbo2

Technical User
Jul 14, 2006
97
GB
Hi all,

Is there an easy way to print out a c# variable from the code behind in my HTML text without using a textbox?

In classic ASP it was <#= variable_name #> (or something like that).

Can you do this in ASP.net?

ta
C
 
there are a variety of ways to do this
response.write
assign the value to any type of control visual control
<%=MyVariable%>. this requires a public property so the code behind would look like this
Code:
public call MyPage : Page
{
   public MyVariable { { get return "Hello World"; } }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason, for your help.
I am having trouble getting the above to work.
It is throwing errors, it complains about the semicolons and {} positions but I can't get it to work.

The situation is that I have done a load of number crunching in the code behind and have ended up with two INTs that I want to pass to the HTML just to add to the end of a URL as a query string.

Thanks
C

 
the code i provided is c#, if you're using VB you'll need to transpose it.

the server side controls are designed to reduce the mark/server code interaction. if you need the values for a link either use Response.Redirect() or apply the values the to Hyperlink.NavigateURL.

ASP.Net is a drastic change from ASP. while you could code them the same, it's not the way the language was intended to be used.



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Cheers both,
I've used the Hyperlink object.
It works a treat
I've got to get out of the classic ASP mind set.
ta
C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top