Hi All,

I design a datagrid which enabled user to edit,delete and add new record inside the grid.

The add button and textbox control embeded in datagrid footer section.

I want to do a validation when user trying to insert new record into database.

What I want to do is check if templatecolumn textbox is blank then pop up a messagebox and

setfocus to textbox until this stage all is fine but when everything completed the page will postback and

reload the text inside textbox and cleared.

I don't want the text inside the textbox clear after BLANK found. It will remain inside the textbox with

unchanged.

Hereon, I posted my html code and code behind.

HTML Code:
  1. <body ms_positioning="GridLayout" id="myBody" runat="server">



ASP Code:
  1. Private Sub dgSchoolName_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgSchoolName.ItemCommand
  2.         Dim pStrSql As String, myds As New DataSet, mydt As DataTable
  3.         Dim Txtbox As TextBox = DirectCast(e.Item.Cells(1).FindControl("txtSchoolNo"), TextBox)
  4.         Dim Txtbox_1 As TextBox = DirectCast(e.Item.Cells(2).FindControl("txtSchoolNameA"), TextBox)
  5.         Dim FTextbox As String = Txtbox.Text
  6.         Dim FTextbox_1 As String = Txtbox_1.Text
  7.         Dim myBody As System.Web.UI.HtmlControls.HtmlGenericControl = CType(Page.FindControl("myBody"), System.Web.UI.HtmlControls.HtmlGenericControl)
  8.  
  9.         If FTextbox = vbNullString Then
  10.             General_F.Setfocus(Txtbox, Page, "Form1")
  11.  
  12.             MsgBox1.alert("School No Cannot Be Blank")
  13.  
  14.             Exit Sub
  15.         ElseIf FTextbox_1 = vbNullString Then
  16.             General_F.Setfocus(Txtbox_1, Page, "Form1")
  17.             MsgBox1.alert("School Name Cannot Be Blank")
  18.  
  19.             myBody.Attributes.Add("onload", "document.getElementById('txtSchoolNo').value = '" & FTextbox & "'")
  20.  
  21.         Exit Sub
  22.         End If
  23. End Sub


I have been posted my code above. I hope someone can help me thanks :-)