Help in converting ASP.net Vb code to ASP.net C# code + Custom validator

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 75
Reputation: mansi sharma is an unknown quantity at this point 
Solved Threads: 0
mansi sharma mansi sharma is offline Offline
Junior Poster in Training

Help in converting ASP.net Vb code to ASP.net C# code + Custom validator

 
0
  #1
Aug 15th, 2009
I have one custom validator, one textbox & one button..I m checking the length of data entered in textbox.

VB CODE
  1. <asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="ValidateThis"
  2. ErrorMessage="The username must be 8" ControlToValidate="TextBox4"></asp:CustomValidator></td>


  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <script runat="server">
  6.  
  7. Sub ValidateThis(ByVal Sender As Object, ByVal args As _
  8. ServerValidateEventArgs)
  9. If Len(args.Value) < 8 Then
  10. args.IsValid = False
  11. Else
  12. args.IsValid = True
  13. End If
  14. End Sub
  15. </script>
  16.  
  17.  
  18. <html xmlns="http://www.w3.org/1999/xhtml" >
  19.  
  20. <head runat="server">


When i click on button,page is postbacked,if the length is less than 8 error msg comes,else nothing.

Mine C# Equivalent code-
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <script runat ="server" >
  6. void ValidateThis(object Sender,ServerValidateEventArgs args)
  7. {
  8. if(len(args.Value)< 0)
  9. {
  10. args.IsValid = false;
  11. }
  12. else
  13. args.IsValid = true ;
  14. }
  15. </script>
  16. <html xmlns="http://www.w3.org/1999/xhtml" >
  17. <head runat="server">


ERROR - The name 'len' does not exist in the current context
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 19
Reputation: chithrasujith is an unknown quantity at this point 
Solved Threads: 3
chithrasujith chithrasujith is offline Offline
Newbie Poster

Re: Help in converting ASP.net Vb code to ASP.net C# code + Custom validator

 
0
  #2
Aug 15th, 2009
  1. <script runat="server">
  2. void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
  3. {
  4. if (args.Value.Length < 8)
  5. {
  6. args.IsValid = false;
  7. }
  8. else
  9. {
  10. args.IsValid = true;
  11. }
  12.  
  13. }
  14.  
  15. </script>
replace your Script with the above code
try this ......
Chithra
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mansi sharma is an unknown quantity at this point 
Solved Threads: 0
mansi sharma mansi sharma is offline Offline
Junior Poster in Training

Re: Help in converting ASP.net Vb code to ASP.net C# code + Custom validator

 
0
  #3
Aug 15th, 2009
very very thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC