Submit button (vb.net) code for form validation

Hi,

I am going thru a lesson to learn how to validate information on a web form.
In the lesson, we are told to use the HTML FileField controls.  Below is the code:

Private Sub validateCategory_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles validateCategory.ServerValidate

If optCategory.SelectedIndex = -1 Then

args.IsValid = False

Else

args.IsValid = True

End If

End Sub

Private Sub ValidateDoc_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles ValidateDoc.ServerValidate

If documentation.PostedFile Is Nothing Then

args.IsValid = False

Else

If Not Path.GetExtension(documentation.PostedFile.FileName) Then

args.IsValid = False

End If

End If

End Sub

Private Sub ValidateAtt_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles ValidateAtt.ServerValidate

If Not attachments.PostedFile Is Nothing Then

If Not Path.GetExtension(attachments.PostedFile.FileName) Then

args.IsValid = False

End If

If attachments.PostedFile.ContentLength > 1000000 Then

args.IsValid = False

End If

End If

End Sub

Private Sub ValidatePic_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles ValidatePic.ServerValidate

If Not picture.PostedFile Is Nothing Then

If Not Path.GetExtension(picture.PostedFile.FileName) Then

args.IsValid = False

End If

End If

End Sub


I need the code for the submit button in order to test the validation.  In the lesson, the instructor forgot to give this information, so in the btnSubmit_Click event (below), I don't know what to code.
 

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

End Sub

Could someone help me out?  Confused <img src=" src="/emoticons/emotion-42.gif">

Thanks! 

0
chqdzn
10/27/2005 2:09:34 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
2379 Views

Similar Articles

[PageSpeed] 1
Get it on Google Play
Get it on Apple App Store

The method Page.Validate() fires all enabled validators. However, you don't need to call it because your Button internally calls it just before calling its Click event (your btnSubmit_Click). You still need to write some validation code in that Click method. You need to know that the page is valid before doing anything with the pages data:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    If Page.IsValid Then
      ' do your work
    End If
End
Sub

Please see this article for a lot of knowledge gathered about validators: http://aspalliance.com/699.

--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
10/27/2005 6:02:44 PM

Thank you, PLBlum.  I wrote this and tested the page:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

If Page.IsValid Then

Validate()

End If

End Sub


I believe I will need more arguments in the btnSubmit_Click event, like if the page is valid, then it should upload the articles the user wants to add to the database.  Do you have an example of that kind of code?  Do I need to step through each control like:


I will check out your link and read your article.  It sounds very interesting and you are the expert.

Thanks for your help and look forward to your help again!  

chqdzn
0
chqdzn
10/28/2005 4:06:57 AM
I believe you misunderstood.

Before btnSubmit_Click is called, the Button internally calls Page.Validate(). You do not need to call it anywhere in your method. In addition, it always gets called before Page.IsValid. Its job is to setup Page.IsValid.

Your job is to develop whatever code you need based on the data coming from the posted page. If that's uploading an article, you will need to learn techniques to do that. I'm sure there are many forum postings and even more articles you can find by searching the web. Just put that code inside the If Page.IsValid Then block.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
10/28/2005 2:55:25 PM
Reply:

Similar Artilces:

Translate c#.net code to vb.net code
Hi I can usually do the translation myself, but this time I am a bit stumped  Let us consider to rewrite Urls (more than 16000 links) using a table. Save original url and rewritten url in a table. Now add a class file in App_Code folder. class UrlRewriteModule : IHttpModule{    public void Dispose()    {        // Nothing to dispose    }    public void Init(HttpApplication context)    {        context.BeginRequest += new EventHandler(context...

How to convert C#.Net code to VB.Net code ???...
HI, i was searching something new, then i suddenly find some tips to convert C#.Net code to VB.Net but i did not do well. i am puttint its url here plz tell me how to convert C#.Net code to VB.Net. http://www.dotnetspider.com/code/C-273-Convert-C-VB-NET.aspx Jasim...Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) It would be better if you write the problem you having, while converting from C# to VB.NET. You cannot completely rely on online converters. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Bl...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

getting start with vb.net and crystal repots(web form)
I use Crystal Report9 in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use Paramater.....how to do that ???? (How do I start to coding --please step by step or sample) please help me !!! Thank you so much!!! very good I have Dropdownlist when I choose the 'month'--> the all data of this field will show I use this Private Sub ddlMonth_Sel...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

How to start coding vb.net(web form and Crystal repotrs)
I use Crystal Report in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use Paramater.....how to do that ???? (please help me step by step,I try it before but not success) please help me !!! There is sample code and tutorials on my blog entry: http://dotnetjunkies.com/WebLog/richard.dudley/archive/2004/05/03/12692.aspxIf my post is your answer, please mar...

How to enable submit or update button using VB.NET 2005 code behind.
ASP.NET 2.0 / VB.NET 2005 I was wondering how would i go about enabling a submit or update button using VB.NET 2005 code behind. Right now I'm able to submit the data when creating a new account, but what I really want to do is have a submit button for a new account or an update button enabled to click when data has been edited.  So, right now I have their enable property set to false. does anyone now how to enable one of the two buttons based on the state I'm using the applcation in. for ex. for new account i want the submit button enabled and the update button hidden...  then f...

How to change vb.net code to C#.Net ?...
Hi, Earlier i had a class  that i got it from this Forum, it in vb.net and i am trying it to convert it in c#.net but i am unable to covert properly to work. the functionality of this class is to convert number value to words. i am putting both of code c#.net and VB.net please rectify it.Public Class NumberToWords Dim Character As String Public Function ConvertNumber(ByVal A As Double) As String On Error Resume Next Dim MM Dim IM ConvertNumber = "" MM = Microsoft.VisualBasic.Len(A) IM = Microsoft.VisualBasic.Left(A, Mic...

How to get RS (From VB6) to .NET (VB.NET)
Hi Friends,         I have requirement, there is one function in VB6 it returns a RS, I need to call that function in  VB.NET, how to get those values into .NET, if can any body can help (pass me some code snippets), that will be greate, Thank you.Madhu... -Madhu hey guys i got this one just by using fill method.-Madhu...

Migrate code from vb.net to C#.net
Hello friends, I had created a web site using visual studio 2005. web site was created using the language vb i.e. VB.net. Now as per the clint requirement I have to migrate all the code in C#. So the question is that is there any tool or any inbuild utility in Visual Stuidio so that we can migrate the site from vb.net to C#.net. Or we have to do it mannually i.e. by changing each and every line of code mannually? Kindly suggest me. Thanks & Regards Girish NehteThanks & RegardsGirish NehteIf This post helps you to solve your problem please mark this as an answer. Hi, at the mome...

How to migrate code from vb.net to c#.net?
Hi all,If anybody knows information on migration of VB.Net application to C#.net. i.e Any tools available, best practices, methodology for estimation. etc.   RegardsHelen    Hey, Take a look at this topic http://forums.asp.net/t/1100603.aspxMaybe some of these sites can be of help to you.  Arnold you can do it by page by page just copy and paste ur page in the following link http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx and convert ur vb.net to c# gotcha!!YasserSpica.www.spica.aewww.bncnetwork.netPlease remember to mark as answers i...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

VB code to VB.Net
I have a contact manager application who has released a SDK that allows outside programs to manipulate its data. The examples are provided for VB and C++ developers. In the VB code examples, there is .bas and .frm files. There are also .vbp and .vbw files. There is also a Global.bas file that looks like it contains the global variables and a public function to handle logins. I have also identified a .scc file that is commented "source code control file". I would like to move this code into the .Net framework if possible, but I would like suggestions on where to start. I'm ge...

Is there a software to convert VB codes to VB.net codes automatically?
hi there! Do anyone of you know if there is any software to convert VB codes to VB.net codes? Or must i maunally convert them? Visual Studio.NET 2000 and 2003 versions automatically convert VB 6 code to VB.NET code, for the most part. Refer to Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic .NET for more information. Hope this helps, AppanASP.NET Team This posting is provided "AS IS" with no warranties, and confers no rights. thanks! =) Is this case same for Visual C codes? Same concept. Refer to Managed Extensions for C++ Migratio...

Web resources about - Submit button (vb.net) code for form validation - asp.net.getting-started

Validation (drug manufacture) - Wikipedia, the free encyclopedia
In the pharmaceutical , medical device , food, blood establishments, tissue establishments, and clinical trials industries, validation is the ...

Serena Williams eyes history, Caroline Wozniacki craves validation in women's US Open final
As Serena Williams eyes another slice of tennis history, Caroline Wozniacki is craving validation with a watershed US Open final triumph on Sunday ...

Travers Duncan asks High Court to strike down ICAC validation laws
ICAC could be sent back to the High Court as a challenge to new laws validating corruption findings looms.

Adam Scott proclaims Texas win as validation of No.1 ranking
... No.1 golfer, beating American Jason Dufner in the third hole of a play-off at the Colonial event. "It's a good feeling and maybe some validation ...

Hollande to sign gay marriage bill after Constitutional Council's validation
Hollande to sign gay marriage bill after Constitutional Council's validation People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, ...

Marketers, Get Ready for the 'Validation Era'
The public brands included has been engaging in a "friends" arms race. But there are signs that we know we overdid it.

Validation and Uncertainty
What an extraordinary conversation I had recently on Twitter. It started with Neil Killick’s statement that we should not consider our stories ...

Nvidia Icera 410 LTE Modem Passes AT&T Network Validation
... Today's news is a small step and logical precursor toward both goals, Nvidia's Icera 410 LTE and HSPA+ baseband has passed AT&T's network validation ...

Ting’s Q1 Subscriber Growth Suffers from Sprint’s New Unlocking Validation Process
Back in February, Sprint updated the process it uses to validate unlocked devices that customers want to utilize on other carriers or one of ...

[Android M Feature Spotlight] Stricter APK Validation Now Actually Checks If All Of An APK's Files Are ...
While you might file this one under "really? We weren't doing this already?" if you're a security expert, Google has added stricter validation ...

Resources last updated: 1/9/2016 11:54:35 PM