Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - onclick event not firing

 
Thread Tools Search this Thread
Old 06-02-2004, 10:46 PM   #1
Default 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




=?Utf-8?B?R2xlbm4=?=
  Reply With Quote
Old 12-23-2004, 04:19 AM   #2
twostepted
 
Posts: n/a
Default Re: onclick event not firing
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



twostepted
  Reply With Quote
Old 12-23-2004, 04:23 AM   #3
No One
 
Posts: n/a
Default Re: onclick event not firing
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"?



No One
  Reply With Quote
Old 12-23-2004, 12:59 PM   #4
=?Utf-8?B?Vmtv?=
 
Posts: n/a
Default Re: onclick event not firing
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.



=?Utf-8?B?Vmtv?=
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Viewer question bootmgr MCITP 0 10-10-2008 02:22 PM
master page does not change due to preinit event not firing franchise63 General Help Related Topics 0 02-13-2008 09:18 AM
RIP HD-DVD? - HD-DVD CES Event Canceled Air Raid DVD Video 0 01-05-2008 03:06 AM
How do find out if a button was clicked before the textchanged event of textbox fires Jack General Help Related Topics 0 10-27-2006 10:19 AM
SUPER BOWL GALA EVENT, tickets available TheLeiterSideYGB DVD Video 1 01-06-2004 11:55 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46