Click here to Skip to main content
11,718,589 members (79,163 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi there fellow CPians,

I am a bit puzzled because a button Click event is not firing and I do not know why.

I have a Gridview wth a bunch of textboxes inside template fields. When I enter a value into any of the textboxes then my submit button click event does not fire, when I remove the values from the textboxes then the submit button click event does fire.

The textboxes onChange event fires a javascript that updates to textboxes in the same row in the grid view.

I need the click event of the submit button to fire after a user has edited the textboxes.

Please advise on how to resolve this issue:

I have created a page with just the neccessary controls to reproduce the issue. Below see my code:

<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FloatConfigurationTestApplication._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
                display: none;
                width: 334px;
                height: 25px;
                height: 25px;
                width: 84px;
    <form id="form1" runat="server">
    <script type="text/javascript" language="javascript">
                function ZeroPad(num, count) {
                    var numZeropad = num + '';
                    while (numZeropad.length < count) {
                        numZeropad = "0" + numZeropad;
                    return numZeropad;
                function UpdateTotals(parentCtrl, isInt, floatPackValue) {
                    var txtMonday = document.getElementById(parentCtrl + '_txtMonday')
                    var txtTuesday = document.getElementById(parentCtrl + '_txtTuesday')
                    var txtWednesday = document.getElementById(parentCtrl + '_txtWednesday')
                    var txtThursday = document.getElementById(parentCtrl + '_txtThursday')
                    var txtFriday = document.getElementById(parentCtrl + '_txtFriday')
                    var txtSaturday = document.getElementById(parentCtrl + '_txtSaturday')
                    var txtSunday = document.getElementById(parentCtrl + '_txtSunday')
                    var txtTotalUnits = document.getElementById(parentCtrl + '_txtTotalUnits');
                    var txtTotalFloatValue = document.getElementById(parentCtrl + '_txtTotalValue');
                    var totalUnits = parseFloat(txtMonday.value== "" ? "0" :txtMonday.value)
                                            + parseFloat(txtTuesday.value == "" ? "0" : txtTuesday.value)
                                            + parseFloat(txtWednesday.value== "" ? "0" :txtWednesday.value)
                                            + parseFloat(txtThursday.value== "" ? "0" :txtThursday.value)
                                            + parseFloat(txtFriday.value== "" ? "0" :txtFriday.value)
                                            + parseFloat(txtSaturday.value== "" ? "0" :txtSaturday.value)
                                            + parseFloat(txtSunday.value == "" ? "0" : txtSunday.value);
                    if (isInt == 0) {
                        txtTotalUnits.value = totalUnits;
                        txtTotalFloatValue.value = totalUnits * floatPackValue
                    else {
                        txtTotalUnits.value = totalUnits.toFixed(2);
                        txtTotalFloatValue.value = (totalUnits * floatPackValue).toFixed(2);

                function QtyUpdated(dayOfWeek) {
                    var ctrlParent = 'grdFloat1_ctl';
                    var ctrlExt = '_txt' + dayOfWeek;
                    var count = 2;
                    var totalUnits = 0;
                    var totalValue = 0;
                    var dayFloatPackValue = 0;
                    var floatPackUnits = 0;
                    var floatPackValue = 0;
                    //DayOfWeek - units cell
                    var txtDay = document.getElementById(ctrlParent + ZeroPad(count, 2) + ctrlExt);
                    while (txtDay != null) {
                        //validate text value - must be numeric
                        if (isNaN(txtDay.value) || txtDay.value == '')
                            txtDay.value = "";
                        var txtFloatValue = document.getElementById(ctrlParent + ZeroPad(count, 2) + '_txtFloatValue');
                        //float pack units
                        floatPackUnits = parseFloat(txtDay.value);
                        //float pack value
                        floatPackValue = parseFloat(txtFloatValue.value);
                        dayFloatPackValue = floatPackUnits * floatPackValue;
                        if (floatPackValue > 0) {
                            //total units for day
                            totalUnits = totalUnits + parseFloat(floatPackUnits);
                            //total value for day
                            totalValue = totalValue + parseFloat(dayFloatPackValue);
                            //total units for float pack
                            UpdateTotals(ctrlParent + ZeroPad(count, 2), 0,floatPackValue);

                        else {
                            txtDay.value = totalUnits;
                            //total units for float pack
                            UpdateTotals(ctrlParent + ZeroPad(count, 2), 0,totalUnits);
                            txtDay = document.getElementById(ctrlParent + ZeroPad(count, 2) + ctrlExt);
                            txtDay.value = totalValue.toFixed(2);
                            //total value for float pack
                            UpdateTotals(ctrlParent + ZeroPad(count, 2), 1);

                        //DayOfWeek - units cell
                        txtDay = document.getElementById(ctrlParent + ZeroPad(count, 2) + ctrlExt);
                    <asp:Label ID="lblFloatType" runat="server" Text="Select Float Type:"></asp:Label>
                    <asp:DropDownList ID="ddlFloatType" runat="server">
        <asp:GridView ID="grdFloat1" runat="server" AlternatingRowStyle-BackColor="LightGray" OnRowDataBound="grdFloat1_OnRowDataBound" >
                <asp:BoundField DataField="AmountTypeId" Visible="false" />
                <asp:BoundField DataField="AmountType" HeaderText="Float Pack" Visible="true" />
                <asp:BoundField DataField="value" HeaderText="Value" Visible="true" />
                <asp:BoundField DataField="Units" HeaderText="Units" Visible="true" />
                <asp:BoundField DataField="Monday" HeaderText="Monday" Visible="false" />
                <asp:BoundField DataField="Tuesday" HeaderText="Tuesday" Visible="false" />
                <asp:BoundField DataField="Wednesday" HeaderText="Wednesday" Visible="false" />
                <asp:BoundField DataField="Thursday" HeaderText="Thursday" Visible="false" />
                <asp:BoundField DataField="Friday" HeaderText="Friday" Visible="false" />
                <asp:BoundField DataField="Saturday" HeaderText="Saturday" Visible="false" />
                <asp:BoundField DataField="Sunday" HeaderText="Sunday" Visible="false" />
                <asp:BoundField DataField="TotalUnits" HeaderText="Total Units" Visible="false" />
                <asp:BoundField DataField="TotalValue" HeaderText="TotalValue" Visible="false" />
                <asp:TemplateField HeaderText="Monday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtMonday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Monday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator3" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtMonday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Tuesday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtTuesday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Tuesday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator4" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtTuesday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Wednesday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtWednesday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Wednesday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator5" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtWednesday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Thursday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtThursday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Thursday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator6" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtThursday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Friday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtFriday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Friday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator7" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtFriday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Saturday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtSaturday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Saturday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator8" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtSaturday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Sunday" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox id="txtSunday" runat="server" Width="100px" BorderStyle="Groove" onchange="javascript: QtyUpdated('Sunday');" ></asp:TextBox>
                        <asp:RegularExpressionValidator id="Regularexpressionvalidator9" runat="server" ValidationExpression="\d{4}"
                            Display="Dynamic" ControlToValidate="txtSunday"></asp:RegularExpressionValidator>
                <asp:TemplateField HeaderText="Total Units" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox ID="txtTotalUnits" runat="server" Width="100px" BorderStyle="Groove" ReadOnly="true" TabIndex="-1" ></asp:TextBox>
                <asp:TemplateField HeaderText="Total Value" ItemStyle-HorizontalAlign="Right">
                        <asp:TextBox ID="txtTotalValue" runat="server" Width="100px" BorderStyle="Groove" ReadOnly="true"></asp:TextBox>
                        <asp:TextBox ID="txtFloatValue" runat="server" Width="100px" BorderStyle="None"></asp:TextBox>
                    <ItemStyle CssClass="row_hide" />
                    <HeaderStyle CssClass="row_hide" />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace FloatConfigurationTestApplication
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        private void LoadGrid()
            DataTable dt = new DataTable();
            dt.Rows.Add(new object[] { "1", "R101", "101", "", "", "", "", "", "", "", "", "", "" });
            dt.Rows.Add(new object[] { "2", "R202", "202", "", "", "", "", "", "", "", "", "", "" });
            dt.Rows.Add(new object[] { "3", "R303", "203", "", "", "", "", "", "", "", "", "", "" });
            dt.Rows.Add(new object[] { "4", "R404", "204", "", "", "", "", "", "", "", "", "", "" });
            grdFloat1.AutoGenerateColumns = false;
            grdFloat1.DataSource = dt;
        protected void grdFloat1_OnRowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                TextBox txtFloatValue = (TextBox)e.Row.Cells[12].FindControl("txtFloatValue");
                txtFloatValue.Text = e.Row.Cells[2].Text;
        protected void Button1_Click(object sender, EventArgs e)
            foreach (GridViewRow row in grdFloat1.Rows)
                string a = ((TextBox)row.Cells[12].FindControl("txtMonday")).Text;
                //int amountType = (int)grdFloat1.DataKeys[row.RowIndex].Value;
                //orderData.Add(amountType, new dailyOrder(day,amountType,int.Parse(((TextBox)row.Cells[12].FindControl("txt" + dayName)).Text)));

Posted 24-May-11 2:06am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I have figured it out, I feel like a complete dumbass now. My regular expression validator did not have an error message so I never noticed that my regular expression was not what I wanted.
digital man at 24-May-11 10:15am
Have a 5 for admitting that you're as fallible as the rest of us! :-)
thatraja at 24-May-11 12:08pm
5 for the self effort
Steve van Niman at 9-Aug-11 8:53am
Thank You, Thank You, Thank You! I had removed a couple of text boxes from my web form, only to find the Submit button would not fire. Turns out, I had not removed the expression validator. Removed, and all is firing again. Sorry you had to run into this first.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

In my case none of the events (either button or check box) were firing. I was able to overcome by this problem using following way.

In my master page I had closed a <script> tag referring to an external .js file with /> notation instead of <script></script>.

for Ex: chanage <script src='../../Scripts/common/menu.Js' type='text/javascript' /> to <script src='../../Scripts/common/menu.Js' type='text/javascript' ></script>

Hope this will help you,
Mohd Zubair Khan at 2-Jul-13 3:09am
Sucram thanks you made my bday... great answer..........
manimaran4187 at 9-Jul-13 6:53am
i have a <input tag with id and input name and ait = go and src =".jpg" like this it is not having onclick event .am not able to fire the button. is there any way to fire input type = image.
PrasadShastri at 14-Jan-14 4:54am
Ramesh, Thanks for sharing. It worked for me.
It is a little thing which most of us never think as solution on such issue,
but it is a correct in my case solution !!!! :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Start here[^].
sucram at 24-May-11 9:18am
Thanks, figured it out eventually I forgot to add an errormessage to the validator and my regular expression was not exactly what I wanted it to be.

The user input failed validation without notifying me, hence the postback did not fire. I also only noticed that the regular expression was not what I wanted it to be after I added the error message to the validator.
Teju MB at 4-Oct-12 5:28am
my 5! was in same situtaion..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 1 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100