Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am using 3 buttons in my aspx page. In that 3 buttons one of the button is not firing an event.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/EuroFlexMaster.master" Title="Remarks Master" Theme="Flex" CodeFile="Remarks_Master.aspx.cs" Inherits="GRNMaster_Remarks_Master" %>

 <div id="Dia Master">
        <fieldset style="width: 90%; height: 95%;">
            <legend style="width: 130px; text-align: center; color: #9900ff; font-size: 14px;">New Remarks</legend>
            <table border="0" style="height: 90%; width: 111%">
                <tr style="height: 25px">
                    <td colspan="5"></td>
                </tr>
                <tr>
                    <td style="width: 25%; height: 92px;"></td>
                    <td style="width: 9%; height: 92px;">
                        <label id="lblRemarks">Remarks</label>
                    </td>
                    <td style="height: 92px; width: 25%;">
                        <asp:TextBox runat="server" ID="txtRemarks" TextMode="MultiLine" MaxLength="240" Width="100%" Height="100%"></asp:TextBox><br />
                    </td>
                    <td style="width: 12%; height: 92px;">   
                             <asp:RequiredFieldValidator ID="ReqRemarks" runat="server" ForeColor="Red" ControlToValidate="txtRemarks" ErrorMessage="Enter Remarks" SetFocusOnError="true" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
                    </td>
                    <td style="width: 217px; height: 92px;"></td>
                </tr>
                <tr>
                    <td style="height: 25px; width: 25%;"></td>
                    <td style="height: 25px; width: 9%;"></td>
                    <td valign="top" align="right" style="height: 25px; width: 25%;"></td>
                    <td valign="top" align="right" style="height: 25px; width: 12%;"> </td>
                    <td style="height: 25px; width: 217px;"></td>
                </tr>
                <tr>
                    <td style="height: 25px; width: 25%;"> </td>
                    <td style="height: 25px; width: 9%;"></td>
                    <td valign="top" align="right" style="height: 25px; width: 25%;">
                        <center>
                            <asp:Button runat="server" ID="btnRemarksView" Text="View All" OnClick="btnRemarksView_Click" CausesValidation="false" />
                            <span> </span>
                            <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_Click1"  CausesValidation="true"/>
                            <span> </span>
                            <asp:Button runat="server" ID="Clear" Text="Clear" OnClick="Clear_Click" CausesValidation="false" />
                            <span> </span>
                        </center>
                    </td>
 </tr>

            </table>
        </fieldset>
    </div>


The aspx.cs page is given below.

C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class GRNMaster_Remarks_Master : System.Web.UI.Page
{
protected void Clear_Click(object sender, EventArgs e)
    {
        txtRemarks.Text = "";
        remarkView.Visible = false;
    }
  protected void btnSave_Click1(object sender, EventArgs e)
    {
        MyDBmgr = new MySqlDBMgr();            //Declaring New Instance of DataBase Object

        string cmd = string.Empty;             //String Declaration for DataBase Query
        string cmdInsert = string.Empty;       //String Declaration for DataBase Query
        cmdInsert = "insert into euroflexworkflow.remarksmaster(RemarkName) Values('" + txtRemarks.Text + "')";
        MyDBmgr.RunSqlCommand(cmdInsert, true); //Passing Query to method which Executes query
        FlexUtilities.ShowAlert(this, " Record Inserted Successfully");
        txtRemarks.Text = "";
    }
  protected void btnRemarksView_Click(object sender, EventArgs e)
    {
        Rebind();
    }

    protected void Rebind()
    {
        MyDBmgr = new MySqlDBMgr();   //Declaring New Instance of DataBase Object
        DataSet RemarkDS = new DataSet();
        RemarkDS = MyDBmgr.RunProcedure("getremarksdetails");
        remarkView.DataSource = RemarkDS.Tables[0].DefaultView;
        remarkView.DataBind();
        remarkView.Visible = true;
        Session["myDataset"] = RemarkDS;
        trGrdCount.Visible = true;
    }
}


The View all and Clear buttons are firing an events. But Save button is not firing an event.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 15-Jul-13 2:55am
v4
Comments
Phani Bharadwaj 15-Jul-13 8:45am    
Yes I have tried with brake points also... But it is not fired an event.
nikhil-vartak 15-Jul-13 8:46am    
Doesn't it fire click event even if 'txtRemarks' has value and 'ReqRemarks' passes validation!?
Phani Bharadwaj 15-Jul-13 8:48am    
yes nikihl.. even if txtRemarks has value it doent firing an event.
OriginalGriff 15-Jul-13 8:55am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Phani Bharadwaj 15-Jul-13 9:51am    
Here I tried with keeping CausesValidation="false" then it is working but i require to keep validation in that point... Please tell me if you have any answers....

1 solution

It seems that your master page to other container has some validation controls that are causing error and not letting page postback.

Best Practice - Always define ValidationGroup="SomeName" in Validator Control and use same ValidationGroup in control that suppose to check validation. In you case it is a button. So
What happened now that your button will check validations that has same group as it has.


You should have try this.
 
Share this answer
 
Comments
Phani Bharadwaj 17-Jul-13 4:21am    
Thanks U...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900