setting DIV content programmatically, how??

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

    #1

    setting DIV content programmatically, how??

    Hey

    ASP.NET 2.0

    In my webpage (.aspx) I have this tag:
    <div id="test" class="pageTitl e">Hello World</div>

    I'm wondering how I in Page_Load event can change the "Hello World" text to
    something else...?
    First I need to get a reference to this div tag, so I'm trying this code,
    I'm NOT sure it works:
    System.Web.UI.H tmlControls tttt = (System.Web.UI. HtmlControls)
    System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("test");

    Any suggestions?

    Jeff


  • Eliyahu Goldin

    #2
    Re: setting DIV content programmaticall y, how??

    To use a control on server side you need to set runat=server. Then you can
    refer to it just by id, no need to call FindControl.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]



    "Jeff" <it_consultant1 @hotmail.com.NO SPAMwrote in message
    news:%237o15aQc HHA.2324@TK2MSF TNGP02.phx.gbl. ..
    Hey
    >
    ASP.NET 2.0
    >
    In my webpage (.aspx) I have this tag:
    <div id="test" class="pageTitl e">Hello World</div>
    >
    I'm wondering how I in Page_Load event can change the "Hello World" text
    to
    something else...?
    First I need to get a reference to this div tag, so I'm trying this code,
    I'm NOT sure it works:
    System.Web.UI.H tmlControls tttt = (System.Web.UI. HtmlControls)
    System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("test");
    >
    Any suggestions?
    >
    Jeff
    >
    >

    Comment

    • jwwishart@gmail.com

      #3
      Re: setting DIV content programmaticall y, how??

      Hi Jeff,

      You need a runat="server" attribute to be able to access it
      programatically from the Page_Load method.

      For example:

      ASPX
      <div id="divChangeMe " runat="server"> Hello World</div>

      CODE BEHIND (In Page_Load)
      divChangeMe.Inn erHtml = "Goodby World!";

      N.B. you may have to go from Source to Designer to get access to the
      div tag in the code beind... At least i have to sometimes.

      Hope this helps...

      Justin

      Comment

      • Thomas  Hansen

        #4
        Re: setting DIV content programmaticall y, how??

        On Mar 28, 9:00 am, "Jeff" <it_consulta... @hotmail.com.NO SPAMwrote:
        Hey
        >
        ASP.NET 2.0
        >
        In my webpage (.aspx) I have this tag:
        <div id="test" class="pageTitl e">Hello World</div>
        >
        I'm wondering how I in Page_Load event can change the "Hello World" text to
        something else...?
        First I need to get a reference to this div tag, so I'm trying this code,
        I'm NOT sure it works:
        System.Web.UI.H tmlControls tttt = (System.Web.UI. HtmlControls)
        System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("test");
        >
        Any suggestions?
        Since everybody else has given you perfect answers here I'll just fill
        in the fact that you can get ANY controls (inclusive the body tag,
        title tag etc) to become a "runat='server' " tag...
        This also gives you nice capabilities to use the ~ operator like for
        instance:
        <a href="~/MyPage.aspx" runat="server"> xxx</a>
        This will map to e.g. localhost/MyApp/MyPage.aspx when run in the
        debugger...

        Nifty little trick :)

        Thomas

        --
        Ajax Widgets helps freelancers master AI tools and digital skills with easy guides and tutorials. Learn, grow, and thrive with smart tech solutions.

        ASP.NET 2.0 Ajax Widgets

        Comment

        Working...