LinkBut​​ton的服务器端事件在禁用= true时触发,在UpdatePanel内部,在IE8中触发

时间:2009-08-13 17:27:06

标签: asp.net ajax updatepanel

它正在点击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>

CodeBehind:

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

2 个答案:

答案 0 :(得分:0)

如果用以下代码替换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

答案 1 :(得分:0)

更改此行:

 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"