请帮忙解决以下代码

时间:2014-03-19 05:58:33

标签: vb.net-2010

Iam尝试在网址(localhost / fca / htp / home.aspx)中捕获网页名称。这是第一次有效。当第一次加载页面时,indexofdot取值4为home。但是当页面被刷新或者我们在访问其他页面后再次返回主页时它将获取值5,这是错误的。我尝试了page.ispostback在刷新时跳过但是它不起作用。 提前谢谢

If String.IsNullOrEmpty(PageName) Then 'Probably the home page

        Dim PathComponents As String() = Request.FilePath.Split("/")
        Dim indexOfDot As Integer = PathComponents(PathComponents.Length - 1).IndexOf(".")
        If indexOfDot > -1 Then
            PageName = PathComponents(PathComponents.Length - 1).Remove(indexOfDot)
        End If
    End If

1 个答案:

答案 0 :(得分:0)

将您的代码放在页面加载方法中,或者如果您需要在页面init中执行该函数,请在第一次加载时在隐藏字段中放置一些值,以便您可以轻松地测试隐藏字段的值。的Request.Form