943,954 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 478
  • ASP.NET RSS
Aug 15th, 2009
0

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

Expand Post »
I have one custom validator, one textbox & one button..I m checking the length of data entered in textbox.

VB CODE
ASP.NET Syntax (Toggle Plain Text)
  1. <asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="ValidateThis"
  2. ErrorMessage="The username must be 8" ControlToValidate="TextBox4"></asp:CustomValidator></td>


ASP.NET Syntax (Toggle Plain Text)
  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-
ASP.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 17
Solved Threads: 0
Junior Poster in Training
mansi sharma is offline Offline
75 posts
since Apr 2008
Aug 15th, 2009
0

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

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 4
Newbie Poster
chithrasujith is offline Offline
21 posts
since Jul 2009
Aug 15th, 2009
0

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

very very thanks
Reputation Points: 17
Solved Threads: 0
Junior Poster in Training
mansi sharma is offline Offline
75 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Emailing from a simple web application
Next Thread in ASP.NET Forum Timeline: Hosting of ADO.Net Data Services, but changes $value to a file download





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC