R
Robert Zurer
Why are child controls and text mutually exclusive using ASP.NET?
The code below gives me either one or the other?
private void Page_Load(object sender, System.EventArgs e)
{
Control formMain = this.FindControl("Form1");
Table table = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell();
Button button = new Button();
button.Text = "Button";
formMain.Controls.Add(table);
table.Rows.Add(row);
row.Cells.Add(cell);
cell.Text = "If I assign the text here it will not display";
cell.Controls.Add(button);
cell.Text = "If I assign the text here the button will not display";
}
The workaround to the above is to add a Literal.
Is this an ASP.NET quirk? If i add the html below it works as expected.
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="MendesMatterManager.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="0">
<tr>
<td>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
This Text displays to the right of the button</td>
</tr>
</table>
</form>
</body>
</HTML>
TIA
Robert Zurer
The code below gives me either one or the other?
private void Page_Load(object sender, System.EventArgs e)
{
Control formMain = this.FindControl("Form1");
Table table = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell();
Button button = new Button();
button.Text = "Button";
formMain.Controls.Add(table);
table.Rows.Add(row);
row.Cells.Add(cell);
cell.Text = "If I assign the text here it will not display";
cell.Controls.Add(button);
cell.Text = "If I assign the text here the button will not display";
}
The workaround to the above is to add a Literal.
Is this an ASP.NET quirk? If i add the html below it works as expected.
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="MendesMatterManager.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="0">
<tr>
<td>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
This Text displays to the right of the button</td>
</tr>
</table>
</form>
</body>
</HTML>
TIA
Robert Zurer