Updating the html inside a panel

G

Guest

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>
 
L

Laurent Bugnion [MVP]

Hi,
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
 
A

Aidy

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

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

Walter Wang [MSFT]

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 ([email protected], 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.
 
W

Walter Wang [MSFT]

Hi Flyguy,

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

Regards,
Walter Wang ([email protected], 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top