Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > The code behind file seems to work very strange

Reply
Thread Tools

The code behind file seems to work very strange

 
 
Tony Johansson
Guest
Posts: n/a
 
      12-15-2010
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">
<aspropDownList 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>
</aspropDownList>
</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";
}
}


 
Reply With Quote
 
 
 
 
Vaibhav Gupta
Guest
Posts: n/a
 
      12-16-2010
Hi,

What you are doing is your are replacing the whole of HTML content i.e. the controls on the page with the string "This is a test".
form1.InnerText basically represents the entire HTML content in the form and hence you see the issue.

Just to clarify, why would you want to do it?

Regards,
Vaibhav

Submitted via EggHeadCafe
HTML5 And the Case of the Missing Browsers
http://www.eggheadcafe.com/tutorials...-browsers.aspx
 
Reply With Quote
 
 
 
 
Brian Cryer
Guest
Posts: n/a
 
      12-16-2010
"Tony Johansson" <(E-Mail Removed)> wrote in message
news:ieaujq$nme$(E-Mail Removed)-september.org...
> 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.
--
Brian Cryer
http://www.cryer.co.uk/brian


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help running a very very very simple code olivier.melcher Java 8 05-12-2008 07:51 PM
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM
very Very VERY dumb Question About The new Set( ) 's Raymond Arthur St. Marie II of III Python 4 07-27-2003 12:09 AM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments