Very basic ASP.NET question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Christie

    #1

    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.aStrin gProperty %>

    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 "Profession al 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

  • MS News

    #2
    Re: Very basic ASP.NET question

    Mike

    In your HTML put

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

    In your Codebehind put in C#

    private void Page_Load(objec t sender, System.EventArg s e)

    {

    myStrvar = "Hello Universe";

    Page.DataBind() ; // you need this

    // Put user code to initialize the page here

    }

    "Mike Christie" <mikec@athensgr oup.com> wrote in message
    news:VQidneobwe-nhq2iRTvUpQ@gig anews.com...[color=blue]
    > I've got some Java experience but no JSP or ASP and am trying to get to[/color]
    grips[color=blue]
    > 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[/color]
    obtained[color=blue]
    > from the database on the screen by binding it to a label. However, if I[/color]
    have[color=blue]
    > an object instantiated in the page's scope, it seems like there should be[/color]
    an[color=blue]
    > easier way to output a string that I obtain from that object. I gather[/color]
    that[color=blue]
    > in JSP there was some syntax like:
    >
    > <%= myObject.aStrin gProperty %>
    >
    > 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 "Profession al C#") while[/color]
    pretty[color=blue]
    > good in many ways is a bit light on detailed ASP examples, and I couldn't[/color]
    find[color=blue]
    > anything about this in the ASP tutorials I looked at.
    >
    > Thanks for any help.
    >
    > Mike
    >[/color]


    Comment

    • John Timney \(Microsoft MVP\)

      #3
      Re: Very basic ASP.NET question

      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.


      nding.aspx

      --
      Regards

      John Timney (Microsoft ASP.NET MVP)
      ----------------------------------------------
      <shameless_auth or_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_autho r_plug>
      ----------------------------------------------

      "Mike Christie" <mikec@athensgr oup.com> wrote in message
      news:VQidneobwe-nhq2iRTvUpQ@gig anews.com...[color=blue]
      > I've got some Java experience but no JSP or ASP and am trying to get to[/color]
      grips[color=blue]
      > 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[/color]
      obtained[color=blue]
      > from the database on the screen by binding it to a label. However, if I[/color]
      have[color=blue]
      > an object instantiated in the page's scope, it seems like there should be[/color]
      an[color=blue]
      > easier way to output a string that I obtain from that object. I gather[/color]
      that[color=blue]
      > in JSP there was some syntax like:
      >
      > <%= myObject.aStrin gProperty %>
      >
      > 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 "Profession al C#") while[/color]
      pretty[color=blue]
      > good in many ways is a bit light on detailed ASP examples, and I couldn't[/color]
      find[color=blue]
      > anything about this in the ASP tutorials I looked at.
      >
      > Thanks for any help.
      >
      > Mike
      >[/color]


      Comment

      • MS News

        #4
        Re: Very basic ASP.NET question

        Sorry missed declaring 'myStrvar'

        protected string myStrvar;

        private void Page_Load(objec t sender, System.EventArg s e)

        {

        myStrvar = "Hello Universe";

        Page.DataBind() ;

        // Put user code to initialize the page here

        }

        "MS News" <sql_agentman@h otmail.com> wrote in message
        news:%23Rj$lf5W DHA.1004@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Mike
        >
        > In your HTML put
        >
        > <asp:Label ID="lblID" runat="server"> <%# myStrvar %></asp:Label>
        >
        > In your Codebehind put in C#
        >
        > private void Page_Load(objec t sender, System.EventArg s e)
        >
        > {
        >
        > myStrvar = "Hello Universe";
        >
        > Page.DataBind() ; // you need this
        >
        > // Put user code to initialize the page here
        >
        > }
        >
        > "Mike Christie" <mikec@athensgr oup.com> wrote in message
        > news:VQidneobwe-nhq2iRTvUpQ@gig anews.com...[color=green]
        > > I've got some Java experience but no JSP or ASP and am trying to get to[/color]
        > grips[color=green]
        > > 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[/color]
        > obtained[color=green]
        > > from the database on the screen by binding it to a label. However, if I[/color]
        > have[color=green]
        > > an object instantiated in the page's scope, it seems like there should[/color][/color]
        be[color=blue]
        > an[color=green]
        > > easier way to output a string that I obtain from that object. I gather[/color]
        > that[color=green]
        > > in JSP there was some syntax like:
        > >
        > > <%= myObject.aStrin gProperty %>
        > >
        > > that would substitute the value of this as a literal in the middle of[/color][/color]
        the[color=blue][color=green]
        > > html. I tried this syntax in ASP.NET with no luck; is there something
        > > analogous? The reference I'm using (Wrox's "Profession al C#") while[/color]
        > pretty[color=green]
        > > good in many ways is a bit light on detailed ASP examples, and I[/color][/color]
        couldn't[color=blue]
        > find[color=green]
        > > anything about this in the ASP tutorials I looked at.
        > >
        > > Thanks for any help.
        > >
        > > Mike
        > >[/color]
        >
        >[/color]


        Comment

        Working...