2015-06-19 19 views
0

我正在網站中添加博客。那樣的工作就好像我將通過查詢字符串的幫助點擊標題鏈接,標題爲desc,img的頁面將會顯示。但在此特定時間循環執行兩次。 這裏是我的代碼,請幫助。循環和查詢正在執行兩次

Private Sub sbloadBlog() 
    Try 
     Dim unqstr As String = Request.QueryString("id").ToString() 
     unqstr = unqstr.Substring(0, unqstr.IndexOf("-")) 
     Dim x As String = "select distinct Title as url, img, blog_desc from Blog_Gallery_AYS where unqid ='" + unqstr + "'" 
     Dim dt As New DataTable 
     dt = Dal.GettDS(x).Tables(0) 
     x = "" 
     x += "<p>" 
     For Each dr As DataRow In dt.Rows 
      x += "<h2>'" + dr("url") + "'</h2>" 
      x += "<p>'" + dr("blog_desc") + "' </h2>" 
      x += "</br>" 
      x += "</br>" 
      x += "<img src='" + dr("img").ToString().Replace("~/", "") + "'/>" 

     Next 
     x += "</p>" 
     x += x.Replace("'", """") 
     divblogdetail.InnerHtml = x 
    Catch ex As Exception 

    End Try 
End Sub 

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 
    If Not Request.QueryString("id") Is Nothing Then 
     sbloadBlog() 
    End If 
End Sub 
+0

「If not me.IsPostBack」perform sbloadBlog()? – Caveman

回答

1

使用Page.IsPostBack屬性來驗證,如果一個頁面所呈現的第一次或響應回傳被加載。

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 
    If Not Me.Page.IsPostBack Then 
     If Not Request.QueryString("id") Is Nothing Then sbloadBlog() 
    End If 
End Sub 
+0

仍然存在相同的問題。當我在divblogdetail.InnerHtml = x時執行調試問題。請幫助 –