Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 June 4th, 2003, 05:01 AM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rfinks
Default Problem addressing a DataGrid field

I'm trying to address a field in a DataGrid from within a custom validator. The custom validator has parameters as such: "Protected Sub ValidateDescLength(source As Object, args As System.WebUI.WebControls.ServerValidateEventArgs). The field is called "Description" in the ItemTemplate and txtDescription in the EditItemTemplate.

If I try to use txtDescription in the customvalidator routine I get a compile error: "Field not defined". I know how to use e.Item.FindControl("field name") but I'm not passing the e parameter in this case. Should I be able to address txtDescription or should I be using some other technique?

Roger
 
Old June 5th, 2003, 09:24 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to james_sellwood
Default

Not sure if this will help, but the way I do it (may not suite your coding style) would be to directly check the string length of the element within the onUpdateCommand Sub-Procedure which has been called from the datagrid, in the form of:

Code:
Sub updateDG(Sender as Object, e as DataGridCommandEventArgs)
    Dim currentTextbox as Textbox
    currentTextbox = e.Item.FindControl("txtDescription")
    If (currentTextbox.text.length < 5) Then
        ' code to generate error message
        ' code to reset the datagrid
        Exit Sub
    End If

    'Code to update the datasource based on correct length ...
End Sub
I find this a more direct method.



--------------------
:) James Sellwood :)
--------------------
 
Old June 5th, 2003, 01:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rfinks
Default

James, thanks for your reply. It makes perfect sense and is as you say a more direct way to accomplish the same thing. I may end up rewriting my code but would like to know how to use the custom validator to edit a field in a data grid. I think in the long run it would make my code much simpler for complicated edits.

Roger





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid truncating field values with apostrophes jrobbins ASP.NET 1.0 and 1.1 Professional 3 December 4th, 2007 08:24 PM
query to get same field twice in datagrid Aneri ASP.NET 1.0 and 1.1 Basics 1 March 1st, 2007 05:56 PM
Addressing form from module MKri VB.NET 2002/2003 Basics 18 December 23rd, 2005 10:22 AM
Inserting text from datagrid into Memo field in c# kgriffin Classic ASP Databases 0 May 4th, 2005 10:17 AM





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