开发者

How can I make a validation icon appear beside a asp:textbox?

开发者 https://www.devze.com 2022-12-18 08:13 出处:网络
Using this code, I can get a very cheesy red lettered message. <form id=\"frmValidator\" action=\"required.aspx\" method=\"post\" runat=\"server\">

Using this code, I can get a very cheesy red lettered message.

<form id="frmValidator" action="required.aspx" method="post" runat="server">    
    Enter Your Name:
    <asp:TextBox id="txtName" runat="server" />
    <asp:RequiredFieldValidator id="valTxtName" ControlToValidate="txtName" Erro开发者_运维知识库rMessage="Please enter your name!" runat="server" />

    <br />
    <asp:button id="btnSubmit" text="Submit" runat="server" />

</form>

Is there some way for me to have a green icon (I have that image so I imagine I just have to reference it) sort of fade into existence beside the control?

Thanks a bunch. :)


You set the ErrorMessage property to a link to an image

e.g. ErrorMessage='<img src="error.gif">'

See this MSDN article.


You can do this

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_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></title>
    <style type="text/css">
        </style>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            BorderStyle="None" ControlToValidate="TextBox1" CssClass="newStyle1"></asp:RequiredFieldValidator>
    </div> 
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
</body>
</html>

.newStyle1
{
    background-image: url('Pic.png');
    width: 500px;
    height: 300px;
}

So basically just don't have any text for the error message and set the css property in the validation controls to have a css class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号