我有一个使用bootstrap和bootstrap验证器的ASP.NET webform。客户端验证似乎正在工作,但是在调用btn_click事件处理程序时不会显示错误消息。相反,Catch响应在页面上呈现HTML。
我是ASP.NET的新手,我对VB知之甚少。帮助赞赏。
ASPX:
<div class="form-group has-feedback">
<label class="control-label col-sm-6" for="ProxSearcb">Records</label>
<div class="col-sm-6">
<asp:TextBox ID="ProxSearch" Runat="Server"
CausesValidation="true"
CssClass="form-control col-sm-6"
TextMode="SingleLine"
Text="5"
ToolTip="Enter the number of records"
AutoPostBack="false"
data-bv-notempty="true"
data-bv-notempty-message="The number of records is required and cannot be empty" >
</asp:TextBox>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToValidate="ProxSearch"
Operator="DataTypeCheck"
Type="Integer"
EnableClientScript="True"
Display="Dynamic"
ErrorMessage="Number of records must be a whole number"
ValidationGroup="InvCalcGroup">
<span class="glyphicon glyphicon-remove red form-control-feedback"></span>
</asp:CompareValidator>
<asp:RequiredFieldValidator ID="rfdProxSearch" runat="server"
ControlToValidate="ProxSearch"
Display="Dynamic"
EnableClientScript="True"
ErrorMessage="Number of records is required"
ValidationGroup="InvCalcGroup">
<span class="glyphicon glyphicon-remove red form-control-feedback"></span>
</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rngProxSearch" runat="server"
ControlToValidate="ProxSearch"
Display="Dynamic"
MinimumValue="1"
MaximumValue="10"
Type="Integer"
EnableClientScript="True"
ErrorMessage="Number of records must be between 1 and 10"
ValidationGroup="InvCalcGroup">
<span class="glyphicon glyphicon-remove red form-control-feedback"></span>
</asp:RangeValidator>
</div>
</div>
VB:
Partial Class ...
Inherits System.Web.UI.Page
Public Shared anSqlStmt As String
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
'adsShowingQuery defined on the web page
'The DataFile attribute must be set on the web page for sorting and paging to work.
If Not Page.IsValid Then
Exit Sub
End If
Dim KeyNames(0) As String
KeyNames(0) = "propno"
adsShowingQuery.SelectCommand = "SELECT TOP " & ProxSearch.Text
adsShowingQuery.SelectCommand &= " propno, street, city, state, zip, nobdrms, nobathrms, sqft, garagesize, mtnview, pool, askprice, "
adsShowingQuery.SelectCommand &= "Round(sqr("
If maxAskPrice.Text <> "" Then
adsShowingQuery.SelectCommand &= "(((askprice - " & maxAskPrice.Text & ")/1000000)^2) + "
End If
If minNoBdrms.Text <> "" Then
adsShowingQuery.SelectCommand &= "(((nobdrms - " & minNoBdrms.Text & ")/6)^2) + "
End If
If minNoBathrms.Text <> "" Then
adsShowingQuery.SelectCommand &= "(((nobathrms - " & minNoBathrms.Text & ")/5)^2) + "
End If
If minSQFT.Text <> "" Then
adsShowingQuery.SelectCommand &= "(((sqft - " & minSQFT.Text & ")/6000)^2) + "
End If
If minGarSize.Text <> "" Then
adsShowingQuery.SelectCommand &= "(((garagesize - " & minGarSize.Text & ")/4)^2) + "
End If
adsShowingQuery.SelectCommand &= "iif(pool = " & hasPool.Checked.ToString() & ", 0,1) + iif(mtnview = " & hasMtnView.Checked.ToString() & ", 0,1)"
adsShowingQuery.SelectCommand &= "),4) AS distance FROM Property ORDER BY 13"
gvShowing.DataKeyNames = KeyNames
gvShowing.AllowPaging = True
gvShowing.AllowSorting = True
gvShowing.Visible = True
gvShowing.DataSourceID = "adsShowingQuery"
gvShowing.AutoGenerateColumns = True
anSqlStmt = adsShowingQuery.SelectCommand
Try
gvShowing.DataBind()
Catch ex As Exception
Response.Write("Exception in btnSearch_Click when binding to grid <br />")
Response.Write("Access Exception Handler: {0} " & ex.ToString() & "<br />")
Response.Write("SQL statement = " & anSqlStmt)
End Try
End Sub
Protected Sub gvShowing_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvShowing.PageIndexChanging
'The DataFile attribute must be set on the web page for sorting and paging to work.
adsShowingQuery.SelectCommand = anSqlStmt
End Sub
Protected Sub gvShowing_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvShowing.Sorting
'The DataFile attribute must be set on the web page for sorting and paging to work.
adsShowingQuery.SelectCommand = anSqlStmt
End Sub
End Class