By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,135 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,135 IT Pros & Developers. It's quick & easy.

asp:button does not fire event when placed inside asp:table

P: n/a
I had a beautiful script that was running, well, just beautifully. But
then I decided to take a button that fired an event and place it inside
a <asp:table. The event WILL NOT FIRE INSIDE THE TABLE!?! When I move
the button outside the table, it works just fine. Inside the table, it
doesn't. What gives?

Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
WJ
Check the HTML tab to make sure that the Button control that fires the event
is placed inside <FORM>....</FORM>. Or perhaps, the "<asp:table" is not
within the "Form" boundary.

John

<ta*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I had a beautiful script that was running, well, just beautifully. But
then I decided to take a button that fired an event and place it inside
a <asp:table. The event WILL NOT FIRE INSIDE THE TABLE!?! When I move
the button outside the table, it works just fine. Inside the table, it
doesn't. What gives?

Nov 19 '05 #2

P: n/a
Hi,

Post the table markup. There are many reasons. You could be missing a
quote or a bracket. If you cut and paste the button then the ID will
automatically change if you don't erase the button from where it was first.
Check that you have matching opening/closing cell and row brackets. If it
is a large table then create a small one row one cell table. Put the button
in there and make sure it fires. Once you have gained that confidence and
seen it work then start creating your larger table piece by piece until your
button stops working. Whatever you just did before it stopped working is
where your problem is. Be sure to post code or markup next time and you
will receive a much more accurate answer. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

<ta*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I had a beautiful script that was running, well, just beautifully. But
then I decided to take a button that fired an event and place it inside
a <asp:table. The event WILL NOT FIRE INSIDE THE TABLE!?! When I move
the button outside the table, it works just fine. Inside the table, it
doesn't. What gives?

Nov 19 '05 #3

P: n/a
The button is definitely still inside the form, and nothing is being
erased and/or left behind when I move the button in and out of the
table. The procedure of moving the button isn't exactly what you'd
call complex. All I do is drag and drop the <asp:button> code in the
HTML viewer. The code behind the scenes still sees the button. I can
still reference and make visual changes to it. So the object is not
being hidden inside a <table> class somewhere. Why don't the events
fire?

Nov 19 '05 #4

P: n/a
Hi,

Post the code. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

<ta*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
The button is definitely still inside the form, and nothing is being
erased and/or left behind when I move the button in and out of the
table. The procedure of moving the button isn't exactly what you'd
call complex. All I do is drag and drop the <asp:button> code in the
HTML viewer. The code behind the scenes still sees the button. I can
still reference and make visual changes to it. So the object is not
being hidden inside a <table> class somewhere. Why don't the events
fire?

Nov 19 '05 #5

P: n/a
Ok, here is a sample script I created called test.aspx that shows what
I'm taking about. It's in two parts, the aspx and aspx.cs. Click the
button in the first box... and it works. The second one is exactly the
same except it's inside an <asp:table> and it doesn't work. The third
button will make changes to the objects in the <asp:table>.

//test.aspx
<%@ Page language="c#" Codebehind="test.aspx.cs"
AutoEventWireup="false" Inherits="cafgss.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</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="FlowLayout">
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button Outside
Table"></asp:Button></P>

<asp:Table id="Table1" runat="server" GridLines="Both"
CellPadding="5" BorderStyle="Solid"
BorderColor="Black">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox runat="server" ID="TextBox2"></asp:TextBox>
<asp:Button runat="server" ID="Button2" Text="Button Inside
Table"></asp:Button>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
<P>
<asp:Button id="Button3" runat="server" Text="Tease
Box"></asp:Button></P>
</body>
</HTML>

//test.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace cafgss
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "This works!";
}

private void Button2_Click(object sender, System.EventArgs e)
{
TextBox2.Text = "Does this one work?";
}

private void Button3_Click(object sender, System.EventArgs e)
{
TextBox2.Text = "I can play in the box";
Button2.Text = "I can reference you";
}
}
}

Nov 19 '05 #6

P: n/a
Hi,

Add this line between the other two in the InitializeComponent function:

this.Button2.Click += new System.EventHandler(this.Button2_Click);
By the way your Button3 is outside of your <Form> tags. Put it above the
</Form> tag or you'll have more problems. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

<ta*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Ok, here is a sample script I created called test.aspx that shows what
I'm taking about. It's in two parts, the aspx and aspx.cs. Click the
button in the first box... and it works. The second one is exactly the
same except it's inside an <asp:table> and it doesn't work. The third
button will make changes to the objects in the <asp:table>.

//test.aspx
<%@ Page language="c#" Codebehind="test.aspx.cs"
AutoEventWireup="false" Inherits="cafgss.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</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="FlowLayout">
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button Outside
Table"></asp:Button></P>

<asp:Table id="Table1" runat="server" GridLines="Both"
CellPadding="5" BorderStyle="Solid"
BorderColor="Black">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox runat="server" ID="TextBox2"></asp:TextBox>
<asp:Button runat="server" ID="Button2" Text="Button Inside
Table"></asp:Button>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
<P>
<asp:Button id="Button3" runat="server" Text="Tease
Box"></asp:Button></P>
</body>
</HTML>

//test.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace cafgss
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "This works!";
}

private void Button2_Click(object sender, System.EventArgs e)
{
TextBox2.Text = "Does this one work?";
}

private void Button3_Click(object sender, System.EventArgs e)
{
TextBox2.Text = "I can play in the box";
Button2.Text = "I can reference you";
}
}
}

Nov 19 '05 #7

P: n/a
Thanks, that did help. I swear I tried that before though. After
playing with it a little more, it would appear that the events are
automatically removed by Visual Studio every single time I make a
change to the HTML page in design mode. It's most annoying. So my
next question is, can that be stopped? This pile of junk is deleting
code that I add!!! Talk about nerve!

Nov 19 '05 #8

P: n/a
I'll suggest you to check if there is any item left in the"job list"(I'm
using Chinese version so you should find similiar name in English)
The IDE will find certain possible problem and add them there. If something
is left then the designer view can have problem to switch back to your code
view, and doing unsensible changes to your code because somehow you made it
think the changes make senses.

<ta*********@gmail.com> ???
news:11**********************@g14g2000cwa.googlegr oups.com ???...
Thanks, that did help. I swear I tried that before though. After
playing with it a little more, it would appear that the events are
automatically removed by Visual Studio every single time I make a
change to the HTML page in design mode. It's most annoying. So my
next question is, can that be stopped? This pile of junk is deleting
code that I add!!! Talk about nerve!

Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.