Visual Studio .NET - Trying to exit Update Command if text box value isn't valid

Asked By C C
31-Jan-07 02:08 PM

Here's my code, but it's not getting caught:

If Len(Trim(txtASBRes.Text)) > 0 And InStr(txtASBRes.Text, "|") = 0 Then

'Means there are characters for the person's code
' and no pipecleaner = didn't use ddl for name


lblResCodeWarn.Visible = True
lblResCodeWarn.Text = "* Use list!"
Exit Sub
End If

If the user just types something in and doesn't use the autosuggest text box, then I want to tell them via a warning they need to use the values from the dropdown list.  The above code isn't getting caught though.

Any suggestions are welcome!

Thanks!

Use GridView.OnRowUpdating event  Use GridView.OnRowUpdating event

31-Jan-07 02:28 PM
The OnRowUpdating event gives you a "last chance" effort to abort the update. In this event, add your code above and also include an e.Cancel = True or whatever value you assing to your GridView event args.

it's a 1.1 datagrid  it's a 1.1 datagrid

31-Jan-07 02:31 PM

...and....it's my datagrid update command.  Forgot to mention that before I think.

If the user tries to update a name, and doesn't use the autosuggest text box's dropdown list, then I wanna exit the sub and display the error message.

Swap out for ItemCommand instead...  Swap out for ItemCommand instead...

31-Jan-07 02:36 PM
Gotcha, sorry about that.

Instead of using the DataGrid's build in update command, create your own link button and use the CommandName and CommandArgument properties to create your own update procedure. For instance, the CommandName might be "CCUpdate" and the CommandArgument is the primary key for that row.

Then consume the DataGrid.ItemCommand event and check for the "CCUpdate" command. From there you can determine whether or not they have done things properly and update/display label as needed.
..same result  ..same result
31-Jan-07 02:57 PM
I just copied / cut all the code from the UpdateCommand into the Itemcommand and it does the same thing.  The "Exit Sub" isn't getting caught.
Shouldn't need Exit Sub anymore  Shouldn't need Exit Sub anymore
31-Jan-07 03:11 PM
With the ItemCommand, you can update or just display the labels. I'm envisioning seeing something like this:

Sub ProcessCommand(sender As Object, e As DataGridCommandEventArgs) Handles DataGrid.ItemCommand

Select Case e.CommandName

Case "CCUpdate" If Len(Trim(txtASBRes.Text)) > 0 And InStr(txtASBRes.Text, "|") = 0 Then

'Means there are characters for the person's code
' and no pipecleaner = didn't use ddl for name

lblResCodeWarn.Visible = True
lblResCodeWarn.Text = "* Use list!" Else UpdateData(e.Item.Cells(2), e.Item.Cells(3)) Case Else ' Do nothing. End Select End Sub
Thanks Sean!  Thanks Sean!
31-Jan-07 03:55 PM

Sean,

You gave me an idea, and it was related to my code.

If there was no "|", I wasn't handling it properly when I ran a database query to make sure the user didn't select a name, then try to edit it on the fly.

So, I needed to say if there's no "|" and the len() > 0, then "NO WAY" & exit the sub

else

if there is a "|" and the len() > 0, then do the db check.

Sorry for the confusion!

Good to hear... Happy to help C C!  Good to hear... Happy to help C C!
31-Jan-07 04:14 PM
end of post
Create New Account
help
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not