【问题标题】:How to disable image button onlclick in asp.net?如何在 asp.net 中禁用图像按钮 onclick?
【发布时间】:2014-02-20 10:50:40
【问题描述】:

我在这个 GridView 中有一个 GridView,有一个列用于使用 asp:CalendarExtender 选择日期。我在 GridView 中有多行是动态生成的。 当我单击图像按钮时,日历会弹出并选择我的日期。

在某些行中,我希望用户在单击该行的图像按钮时选择日期。有时我不想让他选择日期。 当他试图更改日期或单击图像按钮时,他应该收到警告消息,说您不允许更改日期。 我想从客户端处理它。所以请建议我如何做到这一点。 这是aspx代码。

<asp:TextBox runat="server" ID="StartDateTime"  CssClass="search_area_text_vm_small" onclick = "javascript:DateClick(this.id);"></asp:TextBox>
                        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/image3.jpg" />
          <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTime"  PopupButtonID="Image1" Format="yyyy-MM-dd" ></asp:CalendarExtender>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="StartDateTime"
                            ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>

【问题讨论】:

    标签: javascript asp.net gridview ajaxcontroltoolkit calendarextender


    【解决方案1】:

    您可以利用 CalendarExtender 的 OnClientDateSelectionChanged 事件。

    使用下面的代码:

    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTime"  PopupButtonID="Image1" Format="yyyy-MM-dd" OnClientDateSelectionChanged="checkIfDateSelected()" >
    </asp:CalendarExtender>
    
    <javascript>
    function checkIfDateSelected(){
    var dateTextBox=document.getElementByid('StartDateTime');
    if(dateTextBox!='')
    {
    alert ('Date once selected cannot be changed');
    return false;
    }
    </javascript>
    

    如果日期已经选择,这将显示信息弹出并阻止表单提交。

    【讨论】:

    • 如果需要处理客户端脚本,为什么要使用 ImageButton?
    • 它可以是一个 asp 按钮或 ImageButton,因为它们带有 OnClientClick 属性,用于指定在引发 Button 控件的 Click 事件时执行的附加客户端脚本,而 asp Image 则没有。 (对不起,我没有注意到 CalendarExtender,所以我编辑了我的答案)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 2012-08-01
    相关资源
    最近更新 更多