【问题标题】:LinkButton's server-Side event not firing when disabled=true, and inside an UpdatePanel, in IE8LinkBut​​ton 的服务器端事件在禁用 = true 时不会触发,并且在更新面板中,在 IE8 中
【发布时间】:2009-08-13 17:27:05
【问题描述】:

它正在点击 Page_Load 事件,但不是 LinkBut​​ton 的点击:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
            <ContentTemplate>
                <asp:LinkButton ID="btnRenewAll" runat="server" onclick="LinkButton1_Click" OnClientClick="javascript:return ClientMe()">LinkButton</asp:LinkButton>
                <br />
                <asp:Label ID="lblMe" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>



    </div>
    </form>
</body>

<script>
    function ClientMe() {
        var btnRenewall = document.getElementById('<%= btnRenewAll.ClientID %>');
        btnRenewall.disabled = true;
        alert("Hello");
        return true;
    }
</script>

</html>

代码隐藏:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        lblMe.Text = "Checked";
        UpdatePanel1.Update();
    }
}

【问题讨论】:

    标签: asp.net ajax updatepanel


    【解决方案1】:

    如果您将 JS 替换为:

    function ClientMe() {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
        return true;
    }
    
    function startRequest(sender, e) {
        var btnRenewall = document.getElementById('<%= btnRenewAll.ClientID %>');
        btnRenewall.disabled = true;
        alert("Hello");
    }
    

    它应该工作。引用: link text

    【讨论】:

      【解决方案2】:

      改变这一行:

       btnRenewall.disabled = 'disabled';
      

      以下是 HTML 中最小化属性的列表以及它们应如何在XHTML 中编写:

      HTML        XHTML 
      compact     compact="compact"
      checked     checked="checked"
      declare     declare="declare"
      readonly    readonly="readonly"
      disabled    disabled="disabled"
      selected    selected="selected"
      defer       defer="defer"
      ismap       ismap="ismap"
      nohref      nohref="nohref"
      noshade     noshade="noshade"
      nowrap      nowrap="nowrap"
      multiple    multiple="multiple"
      noresize    noresize="noresize"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-10
        • 1970-01-01
        • 2015-05-01
        • 1970-01-01
        相关资源
        最近更新 更多