Asp.net验证与div

时间:2013-01-22 15:50:18

标签: asp.net html

我是asp.net的新手;我尝试将RequiredFieldValidator添加到电话号码部分,但我不能在视觉工作室2010,因为它没有" id"当我在课堂上添加id时,它仍然没有显示。

另外如何在提交按钮上添加onclick?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="odevproje._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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <fieldset>
    <div class="legend"><h3>iletişim</h3></div>
        <div class="form_row">                      
    <div class="form_property form_required">Adınız</div>
    <div class="form_value"><input type="text" size="32" name="name" value="" />                       
          </div>    
        <div class="clearer">&nbsp;</div>
        </div>
        <div class="form_row">                      
             <div class="form_property">Email</div>
           <div class="form_value"><input type="text" size="32" name="email" value="" /></div>
           <div class="clearer">&nbsp;</div>
             </div>
        <div class="form_row">                  
            <div class="form_property">Telefon</div>                                  <div class="form_value"><input type="text" size="32" name="website" value="" /></div>
            <div class="clearer">&nbsp;</div>
        </div>              
        <div class="form_row">                  
            <div class="form_property form_required">Mesaj</div>
                <div class="form_value"><textarea rows="10" cols="46" name="comment"></textarea></div>
                    <div class="clearer">&nbsp;</div>
        </div>
             <div class="form_row form_row_submit">
        <div class="form_value"><input type="submit" class="button" value="Send"/>
            <div class="clearer">&nbsp;</div>
            </div>          
       </fieldset>
    </div>
    </form>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="odevproje._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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <fieldset>

        <div class="legend"><h3>iletişim</h3></div>

            <div class="form_row">

                <asp:TextBox runat="server" id="emailTextBox"/>
                <asp:RequiredFieldValidator runat="server" ControlToValidate="emailTextBox" Text="*" ErrorMessage="Email is required" />

            </div>

            <asp:Button runat="server" id="saveButton" Text="Save" />

    </fieldset>
    </div>

    </form>
</body>
</html>

只显示一个带有RequiredFieldValidator的字段。

答案 1 :(得分:0)

您需要使用asp.net服务器端控件,它在运行时创建html。

例如,您可以使用:

<asp:textbox ID='phonenumber' runat='server'/>
<asp:RequiredFieldValidator ID="ValidateName"
     ControlToValidate="phonenumber"                        
     runat="server" ErrorMessage="Phone Number is required is Required"
     Display=Dynamic>
</asp:RequiredFieldValidator>