473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Very basic ASP.NET question

I've got some Java experience but no JSP or ASP and am trying to get to grips
with ASP.NET. I'd appreciate some help on a simple question.

I have been able to get databinding to work, and can display a string obtained
from the database on the screen by binding it to a label. However, if I have
an object instantiated in the page's scope, it seems like there should be an
easier way to output a string that I obtain from that object. I gather that
in JSP there was some syntax like:

<%= myObject.aStringProperty %>

that would substitute the value of this as a literal in the middle of the
html. I tried this syntax in ASP.NET with no luck; is there something
analogous? The reference I'm using (Wrox's "Professional C#") while pretty
good in many ways is a bit light on detailed ASP examples, and I couldn't find
anything about this in the ASP tutorials I looked at.

Thanks for any help.

Mike

Nov 17 '05 #1
3 1078
Mike

In your HTML put

<asp:Label ID="lblID" runat="server"><%# myStrvar %></asp:Label>

In your Codebehind put in C#

private void Page_Load(object sender, System.EventArgs e)

{

myStrvar = "Hello Universe";

Page.DataBind(); // you need this

// Put user code to initialize the page here

}

"Mike Christie" <mi***@athensgroup.com> wrote in message
news:VQ********************@giganews.com...
I've got some Java experience but no JSP or ASP and am trying to get to grips with ASP.NET. I'd appreciate some help on a simple question.

I have been able to get databinding to work, and can display a string obtained from the database on the screen by binding it to a label. However, if I have an object instantiated in the page's scope, it seems like there should be an easier way to output a string that I obtain from that object. I gather that in JSP there was some syntax like:

<%= myObject.aStringProperty %>

that would substitute the value of this as a literal in the middle of the
html. I tried this syntax in ASP.NET with no luck; is there something
analogous? The reference I'm using (Wrox's "Professional C#") while pretty good in many ways is a bit light on detailed ASP examples, and I couldn't find anything about this in the ASP tutorials I looked at.

Thanks for any help.

Mike

Nov 17 '05 #2
When you are dealing with data objects, you are not really dealing with a
string property, more an item of a datatype that may contain a string. Try
reading this, it explains a lot about databinding and covers the area you
are asking about with soem useful examples and code.

http://www.aspalliance.com/aspxtreme...le-valuedatabi
nding.aspx

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"Mike Christie" <mi***@athensgroup.com> wrote in message
news:VQ********************@giganews.com...
I've got some Java experience but no JSP or ASP and am trying to get to grips with ASP.NET. I'd appreciate some help on a simple question.

I have been able to get databinding to work, and can display a string obtained from the database on the screen by binding it to a label. However, if I have an object instantiated in the page's scope, it seems like there should be an easier way to output a string that I obtain from that object. I gather that in JSP there was some syntax like:

<%= myObject.aStringProperty %>

that would substitute the value of this as a literal in the middle of the
html. I tried this syntax in ASP.NET with no luck; is there something
analogous? The reference I'm using (Wrox's "Professional C#") while pretty good in many ways is a bit light on detailed ASP examples, and I couldn't find anything about this in the ASP tutorials I looked at.

Thanks for any help.

Mike

Nov 17 '05 #3
Sorry missed declaring 'myStrvar'

protected string myStrvar;

private void Page_Load(object sender, System.EventArgs e)

{

myStrvar = "Hello Universe";

Page.DataBind();

// Put user code to initialize the page here

}

"MS News" <sq**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Mike

In your HTML put

<asp:Label ID="lblID" runat="server"><%# myStrvar %></asp:Label>

In your Codebehind put in C#

private void Page_Load(object sender, System.EventArgs e)

{

myStrvar = "Hello Universe";

Page.DataBind(); // you need this

// Put user code to initialize the page here

}

"Mike Christie" <mi***@athensgroup.com> wrote in message
news:VQ********************@giganews.com...
I've got some Java experience but no JSP or ASP and am trying to get to grips
with ASP.NET. I'd appreciate some help on a simple question.

I have been able to get databinding to work, and can display a string

obtained
from the database on the screen by binding it to a label. However, if I

have
an object instantiated in the page's scope, it seems like there should be an
easier way to output a string that I obtain from that object. I gather that
in JSP there was some syntax like:

<%= myObject.aStringProperty %>

that would substitute the value of this as a literal in the middle of

the html. I tried this syntax in ASP.NET with no luck; is there something
analogous? The reference I'm using (Wrox's "Professional C#") while

pretty
good in many ways is a bit light on detailed ASP examples, and I

couldn't find
anything about this in the ASP tutorials I looked at.

Thanks for any help.

Mike


Nov 17 '05 #4

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

Similar topics

9
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
5
by: Lee David | last post by:
I went to the sun site and downloaded what I hope is the development part of java. I downloaded JDK5 with Netbeans. I installed it and now have a folder in my program group "Netbeans". Is that...
10
by: Jason Curl | last post by:
Greetings, I have an array of 32 values. This makes it extremely fast to access elements in this array based on an index provided by a separate enum. This array is defined of type "unsigned long...
6
by: msnews.microsoft.com | last post by:
Hello All, I am very new to ASP.NET and I have a basic question. Can somebody please explain? I have an .aspx Web Page with a textbox control. When the Page initially loads I am calling a...
8
by: pamelafluente | last post by:
Hi, I would like to get some advice. I know enough vb.net on win apps, but I have never worked on web applications and asp.net. I would appreciate if you could indicate the most basic...
6
by: aghazalp | last post by:
hi guys, this would be the most basic question ever...I am not a programmer but I am trying to learn programming in python...I was reading John Zelle's text book and instructed me to make .py file...
17
by: blueapricot416 | last post by:
This is a very basic question -- but I can't find the answer after looking for 20 minutes. If you code something like: function set_It() { setTimeout('Request_Complete("apple", -72)',5000) }...
7
by: Bruno43 | last post by:
Hi I am trying to learn Visual Basic and I am getting everything for the most part, mainly because of my ability to read code like a book, but my question is what is the best way to Navigate through...
56
by: mdh | last post by:
As I begin to write more little programs without the help of the exercises, little things pop up that I need to understand more fully. Thus, below, and although this is not the exact code, the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.