Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2005, 09:49 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default Validation Problem

Hi there,

I have a button that when clicked fires an Insert command. in the past I kept putting blank records into the database so what I thought is to put a validator in.

What happens now is i click the button, it tells me the textbox is required... i put something i click button it says updated... and then when i go to click a button that hides the current panel and opens a new one it won't let me.... says required. in the status bar it has a javascript message. I dont i am doing it right...


Button
--------

Code:
 Private Sub btnAddNews_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNews.Click
        If IsValid Then

            'Convert the article so that it can be into the database.
            Dim ArticleText As String = MyCstr(txtNewsArticle.Text, True, True)
            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Inetpub\wwwroot\davejenkinscouk\davesdatabase.mdb"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
            dbConnection.Open()
            Dim strSQL As String = "INSERT INTO tbl_News(NewsTitle, NewsArticle, NewsImage, NewsLink, NewsComments) values('" & _
              txtNewsTitle.Text & "','" & _
              ArticleText & "','" & _
              txtNewsImage.Text & "','" & _
              txtNewsLinks.Text & "','" & _
              chkComments.Checked & "')"

            Dim myCommand As New OleDb.OleDbCommand(strSQL, dbConnection)

            myCommand.ExecuteNonQuery()
            dbConnection.Close()

            'Rebind the datagrid
            dgNewsArticles.DataSource() = getNewsArticles()
            dgNewsArticles.DataBind()

            'If it inserts correctly then the following is displayed.....
            showNewsMessage.Visible = "True"
            showNewsMessage.Text = "record added successfully."

            'Clear the field values.
            txtNewsTitle.Text = ""
            txtNewsArticle.Text = ""
            txtNewsImage.Text = ""
            txtNewsLinks.Text = ""
            chkComments.Checked = "False"
        End If

    End Sub


with a normal validator there checking the txtNewsTitle.Text box..

cheers


David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
__________________
David Jenkins
 
Old May 26th, 2005, 12:13 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   On the button that you use to hide the panel, set CausesValidation to false.

 
Old May 26th, 2005, 08:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

That will do it... I just want to add that you should be using an object to insert, rather than directly from the aspx page.. this way you can validate at the object, and your business logic (of what's required) isn't tied to the UI... I would also put constraints on the database to prevent blank rows from being inserted.


Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 27th, 2005, 09:41 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Cool - thanks that worked.

A follow on question is ... because I have about 5 hidden panels will all controls on the page then needing setting validtion as false.

Hal following in from what you say.... I should put the insert command into a function then instead? Everytime i try and stop blank inserts going in it goes wrong for me, what is the best way to approach this?

At the moment this is for my personal website so i dont mind it being a bit dirty(?) and direct - hehe. thanks for the tips though!


David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
 
Old May 30th, 2005, 06:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

David,

your aspx page shouldn't talk to the database directly. You should create a business layer (and a data layer) and then bind to the properties on the business side.

The business side, when you tell it to save to the DB, can run a validation against the properties to make sure they are populated before writing out to the DB.

You should also, as I said, set the fields to non-nullable in your backend database.



Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old May 31st, 2005, 04:18 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Cool thanks, I will do that with the database right away. And thanks for the other information I will explore it a little as i dont think i understand this business section (is that just the code behind?) i wouldnt say i am new to this but i am not a pro either.

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521





Similar Threads
Thread Thread Starter Forum Replies Last Post
validation problem Ashleek007 JSP Basics 1 June 18th, 2007 01:16 AM
Validation problem monika.vasvani ASP.NET 1.0 and 1.1 Professional 1 November 25th, 2006 01:44 PM
Interesting validation problem jacob ASP.NET 1.0 and 1.1 Professional 5 February 16th, 2006 07:16 PM
Validation and Insert problem addos Beginning PHP 0 January 17th, 2005 06:50 PM
validation problem Abhinav_jain_mca General .NET 6 August 5th, 2004 02:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.