Updating the html inside a panel

Discussion in 'ASP .Net' started by =?Utf-8?B?Rmx5Z3V5?=, Jan 12, 2007.

  1. 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.dtd">

    <script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
    Panel1.innerHTML = "<html>Hello World!!!<html>"; //This will not
    work.
    }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled 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="Button1_Click"
    Style="z-index: 102;
    left: 104px; position: absolute; top: 200px" Text="Button"
    Width="176px" />

    </div>
    </form>
    </body>
    </html>
    =?Utf-8?B?Rmx5Z3V5?=, Jan 12, 2007
    #1
    1. Advertising

  2. 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.dtd">
    >
    > <script runat="server">
    >
    > protected void Button1_Click(object sender, EventArgs e)
    > {
    > Panel1.innerHTML = "<html>Hello 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
    Laurent Bugnion [MVP], Jan 12, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?Rmx5Z3V5?=

    Aidy Guest

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

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

    "Flyguy" <> wrote in message
    news:...
    > 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.dtd">
    >
    > <script runat="server">
    >
    > protected void Button1_Click(object sender, EventArgs e)
    > {
    > Panel1.innerHTML = "<html>Hello World!!!<html>"; //This will not
    > work.
    > }
    > </script>
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled 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="Button1_Click"
    > Style="z-index: 102;
    > left: 104px; position: absolute; top: 200px" Text="Button"
    > Width="176px" />
    >
    > </div>
    > </form>
    > </body>
    > </html>
    Aidy, Jan 12, 2007
    #3
  4. 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="Default.aspx.cs"
    Inherits="_Default" %>

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

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
    function test()
    {
    var panel2 = document.getElementById('panel2');
    panel2.innerHTML = "<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 (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    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/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Jan 12, 2007
    #4
  5. Hi Flyguy,

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

    Regards,
    Walter Wang (, 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.
    Walter Wang [MSFT], Jan 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry
    Replies:
    3
    Views:
    521
    Harry Singh
    Nov 10, 2003
  2. HS1
    Replies:
    3
    Views:
    468
  3. HS1
    Replies:
    4
    Views:
    8,273
    Babu Kalakrishnan
    Dec 8, 2004
  4. ma
    Replies:
    3
    Views:
    514
  5. news.rcn.com
    Replies:
    2
    Views:
    1,100
    Roedy Green
    Dec 10, 2007
Loading...

Share This Page