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
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.
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.