tags:

views:

54

answers:

2

Hi,

I am using vb.net.

I am having below code in vb.net

<tr>
    <td >
    DateOfReceiving:
    </td>
    <td>
    <asp:TextBox ID="DateOfReceivingTextBox" runat="server" CssClass="datepicker" Text='<%# Bind("DateOfReceiving","{0:dd/MM/yyyy}") %>' />
    </td>
    <td >
    TokenStartingNumber:
    </td>
    <td>
    <asp:TextBox ID="TokenStartingNumberTextBox" runat="server" Text='<%# Bind("TokenStartingNumber") %>' />     
    </td>
</tr>

Now I want an set validation for mandatoryto the textbox TokenStartingNumberTextBox only If the user had entered the value in DateOfReceivingTextBox.

Please suggest!

Best Regards, Yuv

A: 

Use a CustomValidator

http://msdn.microsoft.com/en-us/library/9eee01cx(VS.80).aspx

and do your logic in the code-behind.

Edit - added

You can also do client side validation in javascript, of course. The details are in the article I linked to.

David Stratton
THanks,I am new for custom validator can I have code for the above problem
MKS
A: 

Hi Guys,

Thanks David!

I solve my above issue using below code. I wrote custom validator.

<tr>
    <td>
    DateOfReceiving:
    </td>
    <td>
    <asp:TextBox ID="DateOfReceivingTextBox" runat="server" CssClass="txtDate" Text='<%# Bind("DateOfReceiving","{0:dd/MM/yyyy}") %>' />
    </td>
    <td>
    TokenStartingNumber:
    </td>
    <td>
    <asp:TextBox ID="TokenStartingNumberTextBox" runat="server" Text='<%# Bind("TokenStartingNumber") %>' />
    <br />                                    
    <asp:CustomValidator ID="ctlTokenStartingNumber" runat="server" Display="Dynamic"
    ControlToValidate="DateOfReceivingTextBox" OnServerValidate="TokenStartValidation"
    ErrorMessage="Please enter Token Starting Number"></asp:CustomValidator>
    </td>
</tr>

And In my Codebehind I used this logic.

Sub TokenStartValidation(ByVal source As Object, ByVal arguments As ServerValidateEventArgs)

If CType(FormView1.FindControl("DateOfReceivingTextBox"), TextBox).Text = "" Then
    arguments.IsValid = True
Else
    arguments.IsValid = False
End If

End Sub

Please have a look and suggest me if something is wrong!

Cheers!

MKS