473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

onclick event not firing

I've got a datalist that includes in each databound row a button to delete that specific record. But for some reason, clicking the button does not trigger the event handler. here's the datalist

<form runat="server"><asp:Label id="lblErrorText" runat="server" cssclass="FormValidationErrorText" enableviewstate="False"></asp:Label><asp:Label id="lblAgreementNbr" runat="server" enableviewstate="False"></asp:Label><br /><br /><br /><asp:datalist id="dlEquipment" runat="server" DataKeyField="EquipmentID" OnItemDataBound="FormatDataListRow"><HeaderTemplat e><table width="800" border="1" ><tbody><tr><td><asp:Label id="lblEquipmentType" runat="server" cssclass="InputLabelText">Equipmen
Type: </asp:Label></td><td><asp:Label id="lblBrand" runat="server" cssclass="InputLabelText">Brand: </asp:Label></td><td><asp:Label id="lblModelNbr" runat="server" cssclass="InputLabelText">Model Number: </asp:Label></td><td><asp:Label id="lblSerialNbr" runat="server" cssclass="InputLabelText">Serial Number: </asp:Label></td></tr></HeaderTemplate><ItemTemplate><tr><td><input id="hdnEquipmentID" type="hidden" name="hdnEquipmentID" runat="server" value='<%#Databinder.Eval(Container.DataItem, "EquipmentID")%>' /><CustomControl:EquipmentDropDown id="ddlEquipmentType" runat="server" SelectedItemValue='<%#Databinder.Eval(Container.Da taItem, "EquipmentTypeID")%>'></CustomControl:EquipmentDropDown></td><td><CustomControl:BrandDropDown id="ddlBrand" runat="server" Filter="showPrivateList" SelectedItemValue='<%#Databinder.Eval(Container.Da taItem, "MfgCode")%>'></CustomControl:BrandDropDown></td><td width="18%"><asp:TextBox id="txtModelNbr" Text='<%#Databinder.Eval(Container.DataItem, "ModelNbr")%>' runat="server"></asp:TextBox><asp:RequiredFieldValidator id="vldModelNbr" runat="server" CssClass="FormValidationErrorText" ErrorMessage="Model Number" ControlToValidate="txtModelNbr" Enabled="False" EnableViewState="True" Display="None"></asp:RequiredFieldValidator></td><td width="18%"><asp:TextBox id="txtSerialNbr" Text='<%#Databinder.Eval(Container.DataItem, "SerialNbr")%>' runat="server"></asp:TextBox><asp:RequiredFieldValidator id="vldSerialNbr" runat="server" CssClass="FormValidationErrorText" ErrorMessage="Serial Number" ControlToValidate="txtSerialNbr" Enabled="False" EnableViewState="True" Display="None"></asp:RequiredFieldValidator></td><td

***************** here's the button *****************
<asp:Button id="btnDelete" CommandName='<%#Databinder.Eval(Container.DataItem , "EquipmentID")%>' runat="server" Text="Delete item"
onClick="btnDelete_Click"></asp:Button></td></tr></ItemTemplate><FooterTemplate><tr><td colspan="5" align="center"><input type="submit" value="submit" />&nbsp;<input type="reset" value="cancel" /></td></tr></tbody></table></FooterTemplate></asp:datalist></form

------------------- Here's the event handle

Sub btnDelete_Click(Sender as ObJect, E as EventArgs
tr
cmd.CommandText = "DELETE FROM equipment WHERE EquipmentID = " & Cint(Sender.CommandName
cmd.ExecuteNonQuery(
lblAgreementNbr.Text = "The selected equipment has been deleted. <a href='AgreementListing.aspx'>Click here</a> to return to the agreement listing.
catch exc as Exceptio
lblAgreementNbr.Visible = Fals
lblErrorText.Text = "An error occurred while trying to delete the equipment.
End Tr
End Su
Nov 18 '05 #1
3 2157
Anyone,

I'm having the same problem. Here is what I've done:

Event Signature:
protected void btnDelete_Click(object sender, System.EventArgs e)

In InitializeComponent:
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);

In .aspx file:
<asp:Button id="btnDelete" CssClass="clsButton" runat="server"
Text="Delete" ToolTip="Permanently delete this message"
OnClick="btnDelete_Click" />

I've tried taking the OnClick="btnDelete_Click" out of the <asp:Button>
tag. I've also tried commenting out the this.btnDelete.Click += new
System.EventHandler(this.btnDelete_Click). Neither has any effect.
I'm never making it into the btnDelete_Click event. Does anyone have
any ideas why?

Thanks,

--twostepted

Nov 19 '05 #2
twostepted wrote:
Anyone,

I'm having the same problem. Here is what I've done:

Event Signature:
protected void btnDelete_Click(object sender, System.EventArgs e)

In InitializeComponent:
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);

In .aspx file:
<asp:Button id="btnDelete" CssClass="clsButton" runat="server"
Text="Delete" ToolTip="Permanently delete this message"
OnClick="btnDelete_Click" />

I've tried taking the OnClick="btnDelete_Click" out of the <asp:Button>
tag. I've also tried commenting out the this.btnDelete.Click += new
System.EventHandler(this.btnDelete_Click). Neither has any effect.
I'm never making it into the btnDelete_Click event. Does anyone have
any ideas why?

Thanks,

--twostepted


Does your <asp:Button /> HTML code have Runat="Server"?

Nov 19 '05 #3
Vko
The event is not raised because the button is in a DataList and the DataList
renamed the children controls ... and so the event isn't catch in the page.

If you want to handle the event you must (C#) :

1/ Rewrite your button as :
<asp:button id="btnDelete" commandName="Delete"
commandArgument='<%#Databinder.Eval(Container.Data Item, "EquipmentID")%>'
runat="server" text="Delete item" >

2/ handle the ItemCommand event from the DataList
this.DataList1.ItemCommand += new EventHandler (DataList1_ItemCommand)

3/ Evaluate the command name from the handler function parameter
private void DataList1_ItemCommand (object sender, DataListCommandEventArgs e)
{
if ( e.CommandName == "Delete")
{
// write your code here
BusinessLayer.Items.Delete (e.CommandArgument);
}
}

Note that commands named : "Update", "Cancel" and "Delete" could be directly
handled by specifics DataList's events : UpdateCommand, CancelCommand and
DeleteCommand.
The ItemCommand is the common event for all command events.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: alien2_51 | last post by:
Can some one tell me why the onclick is firing twice for the radion button and checkbox controls...? <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Testing.aspx.vb"...
13
by: Chris | last post by:
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed? I...
5
by: Michel | last post by:
Hi Group of helpers, Following snippet of code: <HTML> <HEAD> <script> function color(value) { alert(value);
2
by: dave.wayne | last post by:
In a web page I have a div tag that has a onlick event registered through the event listener. However, that same div tag also has a onmousedown - start a drag and drop script The problem I am...
17
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
2
by: =?Utf-8?B?Uml0YUc=?= | last post by:
I posted this question in the C# discussion group but am posting it here also since ASP is involved. I'm new to C# and need some help regarding an onClick event not firing. I have a data grid...
7
by: Moses | last post by:
Hi Everybody, I have a problem with onClick event which works in FF and does not work in IE, Here I have giving the details Please help. I am creating a <aTag. dom_obj =...
21
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have...
9
by: skultetc | last post by:
Hey all, I have a div displayed as a block with an onclick event that shows/ hides a different div underneath it. There is a link within the first div that takes the user to a different page. My...
3
by: ndeeley | last post by:
Hi, I've got a link nested inside a form which, when clicked, should open a new window. Whilst it's doing this it also opens the page in the existing parent window as well. I didn't write the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.