?
Solved

ASP vb.net validation question

Posted on 2011-04-28
4
Medium Priority
?
231 Views
Last Modified: 2012-05-11
I have written a VB net web program.  That does the validation in VB.  However this causes problem with screen re-draw.  My undesrtanding is I need to do this in client side, as a script?  I have numerous fields that check for content, size and in some cases content value is based on other fields on the form.

I have the following vb code for example field,
************************************************
        If mxorg = 0 Then
            If istextwflen(org.Text, 3) = False Then
                MsgBox("ORG can only be 3 character text value!")
                org.Focus()
            Else
                org.Text = UCase(org.Text)
            End If
        Else
            org.Text = "***"
        End If

************************************************
And the ASP side has this;
************************************************
                <td class="specialPanelPositionStyle">
   
                    <asp:TextBox ID="org" runat="server" CssClass="smalltxtbox"
                        MaxLength="3" ToolTip="Enter a 3 Character Origin value." CausesValidation="False">
                       
                        </asp:TextBox>    
                </td>
************************************************
I do not want the build in validation because that puts asterix and message on form.  I want a pop up box.  Do I do this in script? or is there some code I can write in ASP section as shown above?

Sorry if I am not clear.
Thanks
0
Comment
Question by:CPOINT2000
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 35485046
Why not do this on the database side?

Set up your fieldname and give it a character lenght of 3.

Then first of all, then this will look more like this:

                <td class="specialPanelPositionStyle">
   
                    <asp:TextBox ID="org" style="width: 3x;" runat="server" CssClass="smalltxtbox"
                        MaxLength="3" ToolTip="Enter a 3 Character Origin value." CausesValidation="False">
                        (max characther: 3)                      
                        </asp:TextBox>    
                </td>
0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 1000 total points
ID: 35485067
If you insist on clientside script, then this:

<script type="text/javascript"> 
function Count() 
{ 
var count=document.getElementById("org").value.length; 
if(parseInt(count)>3) 
{ 
return true; 
} 
alert("Please Enter 3 charachters"); 
return false; 
} 
</script> 

Open in new window

<asp:TextBox ID="org" onblur="return Count()"  runat="server" CssClass="smalltxtbox"
                        MaxLength="3" ToolTip="Enter a 3 Character Origin value." CausesValidation="False">

Then
0
 

Author Comment

by:CPOINT2000
ID: 35485592
Thanks I will try this suggestion.  Actually size is not an issue, that is already setup on field.  I need to validate to make sure, it is text, or date, or numeric.  In some cases it has to allow blank and or values.  In some validations (for example date from/to field) need to validate field is valid yyyymmdd ad the from is prior to to date, to date is after from date, etc...  Instead of at time form is submitted I like to validate as field lost focus or is changed.  This is a vb program that is already been out for some time, which is being converted to web application, and I am trying to keep same functionality as possible as PC version.  That's why I am insisting on client side validation.  Reason I placed the ASP code there is that was generated by system for the field, I was trying to see if there was any code I could insert in there, case, if condition etc...  However I will try the script example you provided now.  Thanks
0
 

Author Closing Comment

by:CPOINT2000
ID: 35779155
Thanks sorry got side tracked, just got back into code.  This worked.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question