M
Mr Not So Know It All
I'm new to NET. This is probably a simple question. I have a table i
build at runtime (in the page CS file). inside the table is a button.
i built a simple click event handler that isnt firing (not getting the
"I'm Back" response write"). can someone please help me figure out
what im doing wrong?
here is the code
aspx file :
<%@ Page Language="C#" AutoEventWireup="true" Debug="true"
Inherits="outage_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>Outage Site</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="tbl_main" BorderWidth="1" BorderColor="Black"
Width="100%" runat="server" />
</div>
</form>
</body>
</html>
+++++++++++++++++++++++++++++++++++++++++++++++++
CS File
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using dbConnection; // database connection objects
public class outage_default : Page
{
protected Table tbl_main;
void Page_Load(object s, EventArgs e)
{
DropDownList ddl_company = new DropDownList();
ddl_company.SelectedIndexChanged += new
EventHandler(ddl_company_SelectedIndexChanged);
ddl_company.Items.Insert(0,new ListItem("Select a
Company","0"));
ddl_company.Items.Insert(1,new ListItem("Company A","1"));
TableRow tr = new TableRow();
TableCell tc = new TableCell();
Literal lit_label = new Literal();
lit_label.Text = "Company ";
tc.Controls.AddAt(0, lit_label);
tc.Controls.AddAt(1, ddl_company);
tc.ColumnSpan = 2;
tr.Cells.Add(tc);
tbl_main.Rows.Add(tr);
}
void ddl_company_SelectedIndexChanged(object sender, EventArgs e)
{
TableRow tr_01 = new TableRow();
TableCell tc_0101 = new TableCell();
Button btn_submit = new Button();
btn_submit.Text = "Submit";
btn_submit.Click += new EventHandler(btn_SubmitClick);
tc_0101.ColumnSpan = 2;
tc_0101.Controls.AddAt(0, btn_submit);
tc_0101.HorizontalAlign = HorizontalAlign.Center;
tr_01.Cells.AddAt(0, tc_0101);
tbl_main.Rows.Add(tr_01);
}
void btn_SubmitClick(object sender, EventArgs e)
{
Response.Write("I'm Back");
}
}
build at runtime (in the page CS file). inside the table is a button.
i built a simple click event handler that isnt firing (not getting the
"I'm Back" response write"). can someone please help me figure out
what im doing wrong?
here is the code
aspx file :
<%@ Page Language="C#" AutoEventWireup="true" Debug="true"
Inherits="outage_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>Outage Site</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="tbl_main" BorderWidth="1" BorderColor="Black"
Width="100%" runat="server" />
</div>
</form>
</body>
</html>
+++++++++++++++++++++++++++++++++++++++++++++++++
CS File
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using dbConnection; // database connection objects
public class outage_default : Page
{
protected Table tbl_main;
void Page_Load(object s, EventArgs e)
{
DropDownList ddl_company = new DropDownList();
ddl_company.SelectedIndexChanged += new
EventHandler(ddl_company_SelectedIndexChanged);
ddl_company.Items.Insert(0,new ListItem("Select a
Company","0"));
ddl_company.Items.Insert(1,new ListItem("Company A","1"));
TableRow tr = new TableRow();
TableCell tc = new TableCell();
Literal lit_label = new Literal();
lit_label.Text = "Company ";
tc.Controls.AddAt(0, lit_label);
tc.Controls.AddAt(1, ddl_company);
tc.ColumnSpan = 2;
tr.Cells.Add(tc);
tbl_main.Rows.Add(tr);
}
void ddl_company_SelectedIndexChanged(object sender, EventArgs e)
{
TableRow tr_01 = new TableRow();
TableCell tc_0101 = new TableCell();
Button btn_submit = new Button();
btn_submit.Text = "Submit";
btn_submit.Click += new EventHandler(btn_SubmitClick);
tc_0101.ColumnSpan = 2;
tc_0101.Controls.AddAt(0, btn_submit);
tc_0101.HorizontalAlign = HorizontalAlign.Center;
tr_01.Cells.AddAt(0, tc_0101);
tbl_main.Rows.Add(tr_01);
}
void btn_SubmitClick(object sender, EventArgs e)
{
Response.Write("I'm Back");
}
}