开发者

In .net onblur event display message in label, is it possible

i have two textboxs, without enter the values in first tetxbox when iam going to second textbox it showing the message in label beside开发者_StackOverflow textbox . is it possible in dotnet, i don't want alert message , i want show that message in label.

i have written code ,using javascript iam display the alert message in onblur event.


You can use a RequiredFieldValidator control for that.

<asp:RequiredFieldValidator id="rqField1"
   ControlToValidate = "ID of input control to validate"
   InitialValue = "" 
   ErrorMessage = "message to display in ValidationSummary control"
   Text = "message to display in control"
   runat="server" />

See

HOW TO: Use the RequiredFieldValidator Control with Other Validation Controls to Handle Blank Entries

jQuery based solution

$(function(){
            $("#txt1").bind("blur", function(){
                var val = $.trim($(this).val());
                if ( val === "" )
                {
                    $("#spnError").show();
                }
                else
                {
                    $("#spnError").hide();   
                }
            });
        });

<span id="spnError" style="display: none">Please enter valid input</span>
        <input type="text" id="txt1" />
        <input type="text" id="txt2" />


You can attach onblur event to first textbox in Page_Load

textbox1.Attributes.Add("onblur","validate()");

Implement validate method in your aspx file as

<script type="text/javascript">
function validate(){
 //Do validation , show messages etc
}
</script>


You can also try something like

<html>
<head>
<script type="text/javascript">
function Test(txt, label)
{
    if (txt.value == "")
        label.innerHTML = "Wrong Value";
}
</script>
</head>
<body>
    <input type="text" id="txt1" onblur="Test(this, lbl1);"/>
    <label id="lbl1" for="txt1">SomeVal</label>
</body>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜