473,657 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="lblErrorTex t" runat="server" cssclass="FormV alidationErrorT ext" enableviewstate ="False"></asp:Label><asp: Label id="lblAgreemen tNbr" runat="server" enableviewstate ="False"></asp:Label><br /><br /><br /><asp:datalis t id="dlEquipment " runat="server" DataKeyField="E quipmentID" OnItemDataBound ="FormatDataLis tRow"><HeaderTe mplate><table width="800" border="1" ><tbody><tr><td ><asp:Label id="lblEquipmen tType" runat="server" cssclass="Input LabelText">Equi pmen
Type: </asp:Label></td><td><asp:Lab el id="lblBrand" runat="server" cssclass="Input LabelText">Bran d: </asp:Label></td><td><asp:Lab el id="lblModelNbr " runat="server" cssclass="Input LabelText">Mode l Number: </asp:Label></td><td><asp:Lab el id="lblSerialNb r" runat="server" cssclass="Input LabelText">Seri al Number: </asp:Label></td></tr></HeaderTemplate> <ItemTemplate>< tr><td><input id="hdnEquipmen tID" type="hidden" name="hdnEquipm entID" runat="server" value='<%#Datab inder.Eval(Cont ainer.DataItem, "EquipmentID")% >' /><CustomControl :EquipmentDropD own id="ddlEquipmen tType" runat="server" SelectedItemVal ue='<%#Databind er.Eval(Contain er.DataItem, "EquipmentTypeI D")%>'></CustomControl:E quipmentDropDow n></td><td><CustomC ontrol:BrandDro pDown id="ddlBrand" runat="server" Filter="showPri vateList" SelectedItemVal ue='<%#Databind er.Eval(Contain er.DataItem, "MfgCode")% >'></CustomControl:B randDropDown></td><td width="18%"><as p:TextBox id="txtModelNbr " Text='<%#Databi nder.Eval(Conta iner.DataItem, "ModelNbr") %>' runat="server"> </asp:TextBox><as p:RequiredField Validator id="vldModelNbr " runat="server" CssClass="FormV alidationErrorT ext" ErrorMessage="M odel Number" ControlToValida te="txtModelNbr " Enabled="False" EnableViewState ="True" Display="None"> </asp:RequiredFie ldValidator></td><td width="18%"><as p:TextBox id="txtSerialNb r" Text='<%#Databi nder.Eval(Conta iner.DataItem, "SerialNbr" )%>' runat="server"> </asp:TextBox><as p:RequiredField Validator id="vldSerialNb r" runat="server" CssClass="FormV alidationErrorT ext" ErrorMessage="S erial Number" ControlToValida te="txtSerialNb r" Enabled="False" EnableViewState ="True" Display="None"> </asp:RequiredFie ldValidator></td><td

*************** ** here's the button *************** **
<asp:Button id="btnDelete" CommandName='<% #Databinder.Eva l(Container.Dat aItem, "EquipmentID")% >' runat="server" Text="Delete item"
onClick="btnDel ete_Click"></asp:Button></td></tr></ItemTemplate><F ooterTemplate>< 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.Com mandName
cmd.ExecuteNonQ uery(
lblAgreementNbr .Text = "The selected equipment has been deleted. <a href='Agreement Listing.aspx'>C lick here</a> to return to the agreement listing.
catch exc as Exceptio
lblAgreementNbr .Visible = Fals
lblErrorText.Te xt = "An error occurred while trying to delete the equipment.
End Tr
End Su
Nov 18 '05 #1
3 2171
Anyone,

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

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

In InitializeCompo nent:
this.btnDelete. Click += new System.EventHan dler(this.btnDe lete_Click);

In .aspx file:
<asp:Button id="btnDelete" CssClass="clsBu tton" runat="server"
Text="Delete" ToolTip="Perman ently delete this message"
OnClick="btnDel ete_Click" />

I've tried taking the OnClick="btnDel ete_Click" out of the <asp:Button>
tag. I've also tried commenting out the this.btnDelete. Click += new
System.EventHan dler(this.btnDe lete_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.EventArg s e)

In InitializeCompo nent:
this.btnDelete. Click += new System.EventHan dler(this.btnDe lete_Click);

In .aspx file:
<asp:Button id="btnDelete" CssClass="clsBu tton" runat="server"
Text="Delete" ToolTip="Perman ently delete this message"
OnClick="btnDel ete_Click" />

I've tried taking the OnClick="btnDel ete_Click" out of the <asp:Button>
tag. I've also tried commenting out the this.btnDelete. Click += new
System.EventHan dler(this.btnDe lete_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="De lete"
commandArgument ='<%#Databinder .Eval(Container .DataItem, "EquipmentID")% >'
runat="server" text="Delete item" >

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

3/ Evaluate the command name from the handler function parameter
private void DataList1_ItemC ommand (object sender, DataListCommand EventArgs e)
{
if ( e.CommandName == "Delete")
{
// write your code here
BusinessLayer.I tems.Delete (e.CommandArgum ent);
}
}

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
3861
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" Inherits="CustomerRelations.Testing" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>Testing</title> <!--
13
5660
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 have created an Is_Dirty routine checking for field changes on my page then if the user clicks on the "exit" button I check for Is_Dirty = true and want to ask then "do you want to exit without saving?". It's a code behind where if the value of...
5
2279
by: Michel | last post by:
Hi Group of helpers, Following snippet of code: <HTML> <HEAD> <script> function color(value) { alert(value);
2
4706
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 having is that once the drag and drop is complete, the mouse button is released and the onclick event is firing. I've tried returning false from the function dealing with the mouse up and cancelling the event with if (e.stopPropagation)...
17
10192
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
2822
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 that I add a cell to programatically. The cell is a hyperlink and the onClick is set to _doPostBack. In my code I handle the event but when I click on that added hyperlink nothing happens. Here's my code (I'll just show the relevant stuff).
7
13207
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 = document.createElement('a'); dom_obj.setAttribute('href', 'javascript:void(0)'); dom_obj.setAttribute('onclick', 'javascript:test()');
21
13446
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 an explanation? Is this evidence of corruption, or a known side effect? TIA Bruce
9
10023
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 problem is that if the user clicks the link, the onclick is also executed and the div underneath is shown/hidden before the browser changes pages, which makes things a little clunky looking. Is there any way to keep the div's onclick from firing...
3
1903
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 code however, and it worked when not placed in a form. Is the onClick event of the form getting confused with the onclick event of the window? Heres the header code: <script language="javascript" type="text/javascript"> <!--
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.