2014-03-19 83 views
0

Iam試圖捕獲URL(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 

回答

0

把你的代碼在頁面加載方法,或者如果你需要執行的頁面初始化函數,把一些價值在一個隱藏字段在第一負載,這樣就可以很容易地測試Request.Form中隱藏字段的值