0

i am new at asp.net; i try to add RequiredFieldValidator to phone number section, but i cant to its at visual studio 2010 because its not have "id" when i add the id inside the class, its still not showing.

Also how can i add onclick at submit button?

<%@ 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>
4

2 回答 2

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 的字段。

于 2013-01-22T15:58:08.380 回答
0

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

例如,您可以使用:

<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>
于 2013-01-22T16:05:02.517 回答