Validation - How to display just one asterisk at the end.

Last post 08-02-2007 2:07 AM by abhishek2981. 5 replies.

Sort Posts:

  • Validation - How to display just one asterisk at the end.

    07-31-2007, 6:46 AM

    Hi,

    I am applying the RequiredFieldValidator for validating Client’s Surname and Given name.

    My Problem is:

    If the client does not enter any thing and clicks Next button it shows two asterisk (* *) side by side. I want to display just one asterisk at the end.

    Please note that I am using table for designing the form and kept all the validations in the last column.

    Plz let me know your thoughts,

    ~Jagadeesh 


     

  • Re: Validation - How to display just one asterisk at the end.

    07-31-2007, 7:20 AM
    • Loading...
    • moredotnet
    • Joined on 11-24-2006, 12:07 PM
    • Millenium City
    • Posts 752

    Check the errormessage property of the requiredfieldvalidator control

    Vishal Khanna

    .NET Interviews & FAQs @ www.dotnetUncle.com




    Click Mark as Answer if the reply helped you.
  • Re: Validation - How to display just one asterisk at the end.

    07-31-2007, 7:25 AM
    Answer
    • Loading...
    • jackyang
    • Joined on 11-16-2006, 7:27 PM
    • Canada
    • Posts 420

    You can just put the asterisk inside the RequiredFieldValidator: <asp:RequiredFieldValidator runat="server" id="reqSurname" ControlToValidate="txtSurname">*</asp:RequiredFieldValidator>

    Complete code tested below:

     

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>
                        <asp:TextBox runat="server" ID="txtSurname" />
                    </td>
                    <td>
                        <asp:RequiredFieldValidator runat="server" ID="reqSurname" ControlToValidate="txtSurname">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button runat="server" id="btnNext" Text="Next" />
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
    
     
    Jack Yang
    .NET Developer
  • Re: Validation - How to display just one asterisk at the end.

    07-31-2007, 8:17 AM
    • Loading...
    • sujitm
    • Joined on 05-23-2007, 9:01 AM
    • Pune
    • Posts 504

    May be it is displaying asteriks of two validator controls. In that case I think its correct.

    - Sujit

    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Validation - How to display just one asterisk at the end.

    08-02-2007, 1:31 AM

    Hello All,

    Sorry for the delayed reply,

     
    I want to explain my issue more clearly. I am having two RequiredFieldValidator one for Client’s Surname and one for Given name.


    My Problem is:

     

    If the client does not enter any thing and clicks Next button it shows two asterisk (* *) side by side (one for Client’s Surname and one for Given name).  

    I want to display just one asterisk at the end for both the RequiredFieldValidator (Client’s Surname and Given name).

     

    Please let me know how to resolve this issue.

     

  • Re: Validation - How to display just one asterisk at the end.

    08-02-2007, 2:07 AM
    Answer

    Hi,

    at the aspx page disable the validator for the surname with the enable = false.

    and then in the code behind page attach the attributes for the button click to call following client side function with passing the Surname validator 's client id as the parameter

    function test(val)

    {

     

    var myVal = document.getElementById(val);

    var Nametextbox = document.getElementById('NameTextBoxID');

    if(Nametextbox.value != '  ')

    {

     ValidatorEnable(myVal, true);

    }if(Page_ClientValidate() == true)

    {

    return true;

    }

    return false;

     

     

    }

    The idea is to enable the surname validator only when the use has entered the value in the Name field , this way at a time only one validator will fire.

     

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter