验证停止使用隐藏的div

时间:2014-03-18 11:19:29

标签: c# validation webforms

我创建了自己的CRM系统,可以在本地完美运行。但是,当项目上传到我们的Web服务器时,我遇到了一些奇怪的错误。我希望我在这里描述的那个是其他人的催化剂。

有一个部分显示下一个通话按钮,点击按钮,以便您可以修改潜在客户联系人详细信息。这是一个基本的隐藏/显示div切换。我对“amendtext”div中的文本框进行了验证。但是,单击按钮时会完全忽略验证(我正在使用验证组)。删除div上的隐藏/显示,验证工作正常。

enter image description here

enter image description here

这是我用来安排div并调用click来保存事件的代码。我已经删除了所有样式等:

<div>
    <div id="viewtext" runat="server">
        <div class="leadaddress">
            <p><strong><asp:Label ID="lblName" runat="server" Text=""></asp:Label></strong></p>
            <p><asp:Label ID="lblAddress" runat="server" Text=""></asp:Label><br /></p>
        </div>
        <div>
        <p><asp:Label ID="lblLeadTel" runat="server" Text=""></asp:Label></p>
        </div>
        <div class="leaddetailsbut">
            <p><asp:LinkButton ID="clickToAmend" runat="server" OnClick="clickToAmend_Click">Amend Address</asp:LinkButton></p>
        </div>
    </div>

    <div id="amendtext" runat="server">
        <p>
            <label>Company</label>
            <asp:TextBox ID="tbLeadName" runat="server" ></asp:TextBox>
            <asp:CustomValidator 
                ID="CustomValidatorLeadName" runat="server" 
                ControlToValidate="tbLeadName"  
                OnServerValidate="CustomValidatorLeadName_ServerValidate"
                ValidateEmptyText="True"
                ValidationGroup="Lead">
            </asp:CustomValidator>
        </p>
        <p>
            <label class="lblwidth80">Address 1</label>
            <asp:TextBox ID="tbAddress1" runat="server" ></asp:TextBox>
            <asp:CustomValidator 
                ID="CustomValidatorLeadAddress1" runat="server" 
                ControlToValidate="tbAddress1"  
                OnServerValidate="CustomValidatorAddress1_ServerValidate"
                ValidateEmptyText="True"
                ValidationGroup="Lead">
            </asp:CustomValidator>
        </p>
        <p>
            <label class="lblwidth80">Address 2</label>
            <asp:TextBox ID="tbAddress2" runat="server" ></asp:TextBox>
        </p>
        <p>
            <label class="lblwidth80">City</label>
            <asp:TextBox ID="tbCity" runat="server" ></asp:TextBox>
            <asp:CustomValidator 
                ID="CustomValidatorCity" runat="server" 
                ControlToValidate="tbCity"  
                OnServerValidate="CustomValidatorCity_ServerValidate"
                ValidateEmptyText="True"
                ValidationGroup="Lead">
            </asp:CustomValidator>

            <label>Postcode</label>
            <asp:TextBox ID="tbPostcode" runat="server" ></asp:TextBox>
            <asp:CustomValidator 
                ID="CustomValidatorPostcode" runat="server" 
                ControlToValidate="tbPostcode"  
                OnServerValidate="CustomValidatorPostcode_ServerValidate"
                ValidateEmptyText="True"
                ValidationGroup="Lead">
            </asp:CustomValidator>
        </p>

        <div>
            <p>
                <label>Telephone</label>
                <asp:TextBox ID="tbTelephone"  runat="server" ></asp:TextBox>
                <asp:CustomValidator 
                    ID="CustomValidatorTelephone" runat="server" 
                    ControlToValidate="tbTelephone"  
                    OnServerValidate="CustomValidatorTelephone_ServerValidate"
                    ValidateEmptyText="True"
                    ValidationGroup="Lead">
                </asp:CustomValidator>
            </p>
        </div>
        <div>
            <asp:LinkButton ID="clickToSave" runat="server" OnClick="clickToSave_Click" ValidationGroup="Lead">Save Address</asp:LinkButton>
        </div>
    </div>
</div>

代码背后:

protected void Page_Load(object sender, EventArgs e)
{    
    viewtext.Visible = true;  
    amendtext.Visible = false;  
}

protected void clickToAmend_Click(object sender, EventArgs e)
{ 
    viewtext.Visible = false;      
    amendtext.Visible = true;
}    


protected void clcikToSave_Click(object sender, EventArgs e)
{  
    if (this.Page.IsValid)
    {    
        //code to save the change...

        viewtext.Visible = true; 
        amendtext.Visible = false;   
    }       
}

我现在开始拉掉我留下的小头发......

0 个答案:

没有答案