Subject: requiredfieldvalidator
Posted By: suzila Post Date: 1/7/2004 10:05:05 PM
hi every body,

i'm not sure wether i'm in right forum.

(i'm using asp.net)

i have a form and a datagrid.
i'll insert the data using a form (only textbox) and will be displayed by datagrid.
my datagrid have edit and delete function.
to make sure users will key in all required data, so i put requiredfieldvalidator

the main problem:

when i want to edit data, the error msg will appear and stop the edit process..

anyone of u can help me...?

thanks a lot




Reply By: life_s Ng Reply Date: 1/8/2004 6:13:19 AM
do u means when u click edit, and the validator stop u from it?

would u mind to post ur code here for reference?

Regards
life's Ng

Reply By: planoie Reply Date: 1/8/2004 10:44:02 AM
When you have any field validators, they will always validate the choosen control on any event that posts the form.  This is for validation on the client side.  I have found no easy way to disable a validator on a particular button press.  For a simple solution, your options are pretty limited.  If you eliminate validation on the client side and only validate on the server side you could easily disable the validator when you handle a specific button press.  In your scenario, the button's in the datagrid that handle the datagrid item events would disable the validator for the textbox that is outside of the datagrid.  You'd need to disable the validator, check for page validity, then reenable it before you exit the handler so it will actually still validate on the next post.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: stu9820 Reply Date: 1/8/2004 10:53:35 AM
You might want to look into EditItemTemplate.  It won't check the requiredfieldvalidator until after the edit button is clicked.

Also make sure you have

If Not IsPostBack Then
   your_data_grid_bind
End If block.

That way it doesn't refresh your data with every click.

Reply By: suzila Reply Date: 1/8/2004 8:25:27 PM
To - life s Ng:
Here's is my edit code

Private Sub GridDokumen_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles GridDokumen.EditCommand
Response.Cache.SetCacheability(HttpCacheability.NoCache)

  If (Request.Cookies("np") Is Nothing) Then
  Response.Redirect("index.aspx")

  Else

  Menutempahan1.np = Request.Cookies("np").Value
  GridDokumen.EditItemIndex = e.Item.ItemIndex
  myComponent.FillDataSet  (Jenisdok11,myComponent.OleDbDataAdapter1)
  GridDokumen.DataBind()

   End If

    End Sub


'-----------------Thank U


Reply By: life_s Ng Reply Date: 1/9/2004 7:19:55 AM
im not sure is this will help,
1st, u set the validator's Enabled properties to false at the start, then when the user click on edit, u set it back to true.
i was tried to use this b4, but failed, coz the funtion comes up delay 1 step.
(for my case) u might give it a try.

For my dataGrid, i use a loop to check whether there is a blank text box. the example code is like below:

                               dim i,j as integer
                               dim params(3) as string
                               dim strText as string
                               dim blnGo as boolean= true
                               j=0
    
    
                             for i =1 to e.Item.Cells.Count-3
                               strText=Ctype(e.Item.Cells(i).Controls(0), TextBox).Text
    
                              if strText <> "" then  'Check is there any box is empty
                               params(j)=strText
                               j=j+1
                              else
                               lblMessage.Text="u forgot to enter a value!! Update Failed!!"
                               blnGo=false
                              end if
                             next
    
                              if not blnGo then
                               return false
                               exit function
                              end if
    
        dim strsql as string="UPDATE SG SET Name='"& params(0) &"', IC='"& params(1) &"', StaffID='"& params(2) &"', Password='"& params(3) &"' WHERE ID="& Ctype(e.Item.Cells(0).Controls(1), Label).text

if there is a blank text box, it'll prompt the user.
and for the strsql string, its better to use parameters to update it. otherwise, when user type ' or some simbols, it'll show u error.
(prevent sql trancated)learned From Mr.Peter

 
Hope this help
Regards
life's Ng


Go to topic 8367

Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964
Return to index page 963