Protected Sub AccessDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles AccessDataSource1.Inserting
Dim sScript As String
If String.IsNullOrEmpty(e.Command.Parameters("公司名称").Value) Then
sScript = "alert('公司名称不能为空')"
Me.ClientScript.RegisterStartupScript(Me.GetType, "error", sScript, True)
e.Cancel = True
Else
'防止刷新提交
Response.Write(" <script language=javascript> alert( '操作成功 ');window.location.href=window.location.href; </script> ")
End If
End Sub
自己用的,解决录入空格问题
Dim sScript, temp1 As String
If String.IsNullOrEmpty(e.Command.Parameters("公司名称").Value) Then
'判断是真空
sScript = "alert('公司名称不能为空')"
Me.ClientScript.RegisterStartupScript(Me.GetType, "error", sScript, True)
e.Cancel = True
Else
'检查有空格的空情况
temp1 = e.Command.Parameters("公司名称").Value.ToString().Trim() '先去一下空格,需要先判断一下默认是有是空,是真空则提示
If String.IsNullOrEmpty(temp1) Then
sScript = "alert('公司名称不能为空')"
Me.ClientScript.RegisterStartupScript(Me.GetType, "error", sScript, True)
e.Cancel = True
Else
'防止刷新提交
Response.Write(" <script language=javascript> alert( '操作成功 ');window.location.href=window.location.href; </script> ")
End If
End If