在用vb.net开发的security support时,遇到一个问题,在trainingCourses.aspx页面上增加了一个HyperLink控件
<asp:HyperLink runat="server" ID="hlUSOnline" Text="Show Online Training Course" NavigateUrl="/secure/trainingCourses.aspx?c=en-US&o=True"
CssClass="btn btn-info" />
然后在trainingCourses.aspx.vb中增加了一行代码
hlUSOnline.CssClass = "btn btn-success" 结果编译程序时,报错: " ‘hlUSOnline‘ is not declared, It may be inaccessible due to its protection level " 弄了半天也没搞明白是什么原因。
后来Google好久,才发现是因为项目中存在另一个文件trainingCourses - Copy.aspx,这个文件没有对应的vb后台文件存在。它也调用trainingCourses.aspx.vb作为后台文件,这样,在trainingCourses - Copy.aspx中是不存在这个新增的hlUSOnline按钮的,所以就报这个错误
解决方法: 从项目中把trainingCourses - Copy.aspx文件排除就可以了
还有个问题,在程序中写的代码
---------------------------------------------------------------------------------
If ddlCountry.SelectedValue = "en-US" And Request.QueryString("o").ToString <> "" Then
hlUS.CssClass = "btn btn-success"
hlUSOnline.CssClass = "btn btn-success"
------------------------------------------------------------------------------------------
发现报错 object reference not set to an instance of an object ,增加如下代码解决
Try
If ddlCountry.SelectedValue = "en-US" And Request.QueryString("o").ToString <> "" Then
hlUS.CssClass = "btn btn-success"
hlUSOnline.CssClass = "btn btn-success"
End If
Catch ex As Exception
End Try