Updating the html inside a panel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Rmx5Z3V5?=

    Updating the html inside a panel

    How can I update the html inside of a panel?

    How can I make this code work

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <script runat="server">

    protected void Button1_Click(o bject sender, EventArgs e)
    {
    Panel1.innerHTM L = "<html>Hell o World!!!<html>" ; //This will not
    work.
    }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Panel ID="Panel1" runat="server" Height="144px" Style="z-index:
    100; left: 64px;
    position: absolute; top: 48px" Width="256px">
    Say Hello</asp:Panel>
    <asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
    Style="z-index: 102;
    left: 104px; position: absolute; top: 200px" Text="Button"
    Width="176px" />

    </div>
    </form>
    </body>
    </html>
  • Laurent Bugnion [MVP]

    #2
    Re: Updating the html inside a panel

    Hi,

    Flyguy wrote:
    How can I update the html inside of a panel?
    >
    How can I make this code work
    >
    <%@ Page Language="C#" %>
    >
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    >
    <script runat="server">
    >
    protected void Button1_Click(o bject sender, EventArgs e)
    {
    Panel1.innerHTM L = "<html>Hell o World!!!<html>" ; //This will not
    work.
    }
    </script>
    A Panel is rendered on the client by a DIV. You can see that by viewing
    the HTML source sent to the client, always a good idea when something is
    not working properly.

    Since the Panel is a DIV, you may not use the "html" tags again, as they
    are already present in the document.

    HTH,
    Laurent
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch

    Comment

    • Aidy

      #3
      Re: Updating the html inside a panel

      You could use a Literal instead of a panel and set the Text property of the
      literal;

      MyLiteral.Text = "<p>Hello world</p>";

      "Flyguy" <flyguy@nospam. nospamwrote in message
      news:1410085A-71D1-42C2-8978-9E704220BF9A@mi crosoft.com...
      How can I update the html inside of a panel?
      >
      How can I make this code work
      >
      <%@ Page Language="C#" %>
      >
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      >
      <script runat="server">
      >
      protected void Button1_Click(o bject sender, EventArgs e)
      {
      Panel1.innerHTM L = "<html>Hell o World!!!<html>" ; //This will not
      work.
      }
      </script>
      >
      <html xmlns="http://www.w3.org/1999/xhtml" >
      <head runat="server">
      <title>Untitl ed Page</title>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <asp:Panel ID="Panel1" runat="server" Height="144px"
      Style="z-index:
      100; left: 64px;
      position: absolute; top: 48px" Width="256px">
      Say Hello</asp:Panel>
      <asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
      Style="z-index: 102;
      left: 104px; position: absolute; top: 200px" Text="Button"
      Width="176px" />
      >
      </div>
      </form>
      </body>
      </html>

      Comment

      • Walter Wang [MSFT]

        #4
        RE: Updating the html inside a panel

        Hi flyguy,

        I can see your intension is to mark the "Hello World!!!" as html, therefore
        you enclosed it in tag "<html></html>".

        First, innerHTML is not a server-side property, it's a client-side property
        (http://msdn2.microsoft.com/en-us/library/ms533897.aspx). You can use any
        html source to set to this property, for example: <h1>Hello World!!!</h1>.
        However, "<html></html>" is also a valid html tag which normally used in
        the most outside of the html source.

        To set the html inside the Panel at server-side, you can create a literal
        control with the html source and add the control to the Panel:

        LiteralControl lc = new LiteralControl( "<h1>Hello World!!!</h1>");
        panel1.Controls .Add(lc);


        To set the html inside the Panel at client-side, you can use:

        <%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
        Inherits="_Defa ult" %>

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">
        <title>Untitl ed Page</title>
        <script type="text/javascript" language="javas cript">
        function test()
        {
        var panel2 = document.getEle mentById('panel 2');
        panel2.innerHTM L = "<h1>Hello JavaScript!!!</h1>";
        }
        </script>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:Panel ID="panel1" runat="server"> </asp:Panel>
        <asp:Panel ID="panel2" runat="server"> </asp:Panel>
        <input type="button" onclick="test() " value="test" />
        </div>
        </form>
        </body>
        </html>


        Hope this helps.

        Sincerely,
        Walter Wang (wawang@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications. If you are using Outlook Express, please make sure you clear the
        check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
        promptly.

        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Walter Wang [MSFT]

          #5
          RE: Updating the html inside a panel

          Hi Flyguy,

          I'm not sure about your question. Would you please depict more? Thanks.

          Regards,
          Walter Wang (wawang@online. microsoft.com, remove 'online.')
          Microsoft Online Community Support

          =============== =============== =============== =====
          When responding to posts, please "Reply to Group" via your newsreader so
          that others may learn and benefit from your issue.
          =============== =============== =============== =====

          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          Working...