我的脚本无效

时间:2015-03-29 12:19:45

标签: javascript c# asp.net

我在' Save'中调用脚本函数。按钮在特定文本字段为空时显示警报。

脚本:

function validateAddRootCaseForm() {

    if (document.getElementById(GetClientId("txtRoot"))) {
        if (document.getElementById(GetClientId("txtRoot")).value == "") {
            alert("Root is mandatory");
            return false;
        }
    }


    if (document.getElementById(GetClientId("txtDes"))) {
        if (document.getElementById(GetClientId("txtDes")).value == "") {
            alert("Description is mandatory");
            return false;
       }
    }

} 

前端代码:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent"   runat="Server">
    <table class="style1">
        <tr>
            <td class="style2">
                <asp:Label ID="lblRootCaseID" runat="server" Text="Root Cause ID"></asp:Label>
            </td>
            <td class="style6">
                <asp:TextBox ID="txtRootCaseID" runat="server" Height="25px" Width="260px" ReadOnly="true"></asp:TextBox>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td class="style2">
                <asp:Label ID="lblRootDes" runat="server" Text="Root">   </asp:Label>
            </td>
            <td class="style6">
                <asp:TextBox ID="txtRoot" runat="server" Height="25px"  Width="260px"></asp:TextBox>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td class="style2">
                <asp:Label ID="lblDes" runat="server" Text="Description">   </asp:Label>
            </td>
            <td class="style6">
                <asp:TextBox ID="txtDes" runat="server" TextMode="MultiLine" Rows="10" Width="260px"></asp:TextBox>
            </td>
             <td>
                &nbsp;
            </td>
        </tr>
        <tr style="visibility: hidden">
            <td>
            </td>
        </tr>
         <tr style="visibility: hidden">
             <td>
            </td>
        </tr>
        <tr>
            <td class="style5">
            </td>
            <td style="height: 30px">
                <asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return validateAddRootCaseForm()"
                Width="80px" Height="25px" OnClick="btnSave_Click" />
                <asp:Button ID="btnAddNew" runat="server" Text="Add New Root Case" Width="150px" Height="25px"
                OnClick="btnAddNewRootCase_Click" />
                <br />
                <br />
                <br />
            </td>
        </tr>
</table>

但是,当我点击&#39;保存&#39;按钮带有空字段,这些警报不会显示。有人可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:-1)

尝试从按钮调用中删除“返回”