ASP.NET按钮未触发事件 [英] ASP.NET Button is not firing an event

查看:87
本文介绍了ASP.NET按钮未触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在aspx页面中使用了3个按钮。在那3个按钮中,其中一个按钮没有触发事件。

Hi,

I am using 3 buttons in my aspx page. In that 3 buttons one of the button is not firing an event.

<%@ 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>





aspx.cs页面如下:





The aspx.cs page is given below.

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;
    }
}





查看全部和清除按钮正在触发事件。但是保存按钮没有触发事件。



SHOUTING已删除 - OriginalGriff [/ edit]



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

[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

似乎你的主页到其他容器有一些导致错误的验证控件而且不允许页面回发。



最佳实践 - 始终定义ValidationGroup = SomeName在Validator控件中并在控件中使用相同的ValidationGroup,以便检查验证。在你的情况下,它是一个按钮。所以

现在你的按钮将检查具有相同组的验证现在发生了什么。





你应该试试这个。
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.


这篇关于ASP.NET按钮未触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆