Reputation: 13
I am adding blogs in a website. that work like if i will click on the title link by the help of query string the page with title, desc, img will display.but at this particular time loop is executing two time. here is my code pls help.
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
Upvotes: 0
Views: 89
Reputation: 11105
Use Page.IsPostBack property to verify if a page is being rendered for the first time or is being loaded in response to a postback.
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
Upvotes: 1