The code behind file seems to work very strange

T

Tony Johansson

Hello!

I have added a table to the default page using the design mode. In the table
I have added some labels, textBoxes,dropdownlistbox and a button using the
design mode.
When I run this page I can see the table in the browser so all seems to work
fine.

But if I add this statement form1.InnerText = "This is a test";
to the Page_Load statement then the table with the including controls will
not be displayed in the browser.
In the browser will only this text be displayed This is a Test

So my question is how can this row form1.InnerText = "This is a test";
in the Page_Load cause the the table with all the control not to be
displayed ??


<%@ 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="labelEvent" runat="server"
Text="Event:"></asp:Label>
</td>
<td style="width:100px">
<asp:DropDownList ID="dropDownListEvents" runat="server">
<asp:ListItem>SQL Server 2005 and XML</asp:ListItem>
<asp:ListItem>Office 2003 and XML</asp:ListItem>
<asp:ListItem>Introduction to ASP.NET</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="labelFirstname" runat="server"
Text="Firstname:"></asp:Label>
</td>
<td style="width: 100px">
<asp:TextBox ID="textFirstname" runat="server"
Height="16px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="labelLastname" runat="server"
Text="Lastname:"></asp:Label>
</td>
<td style="width: 100px">
<asp:TextBox ID="textLastname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="labelEmail" runat="server"
Text="Email:"></asp:Label>
</td>
<td style="width: 100px">
<asp:TextBox ID="textEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="buttonSubmit" runat="server" Text="Submit"
/>
</td>
</tr>
</table>

</div>
</form>
</body>
</html>

//Code behind file
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
form1.InnerText = "Detta är ett test";
}
}
 
B

Brian Cryer

Tony Johansson said:
Hello!

I have added a table to the default page using the design mode. In the
table I have added some labels, textBoxes,dropdownlistbox and a button
using the design mode.
When I run this page I can see the table in the browser so all seems to
work fine.

But if I add this statement form1.InnerText = "This is a test";
to the Page_Load statement then the table with the including controls will
not be displayed in the browser.
In the browser will only this text be displayed This is a Test

So my question is how can this row form1.InnerText = "This is a test";
in the Page_Load cause the the table with all the control not to be
displayed ??

It sounds like y ou don't understand what assigning to InnerText is doing.

Everything you are putting on your page is inside form1. Assigning to
InnerText replaces all of the content with the supplied test. So:

form1.InnerText = "This is a test";

is saying replace EVERYTHING inside form1 with the text "This is a test". So
it replaces everything (which includes your table) with the given text. So
the table isn't displayed because its no longer there, you've assigned new
content to the form.

If you want to display a message I suggest you use a label.

Hope this helps.
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top