 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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
|
|
|
|

January 7th, 2004, 11:05 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
requiredfieldvalidator
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
__________________
 Suzila
|
|

January 8th, 2004, 07:13 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 8th, 2004, 11:44 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

January 8th, 2004, 11:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

January 8th, 2004, 09:25 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.No Cache)
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
|
|

January 9th, 2004, 08:19 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |