Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax viewstate url , +
Hello,

I am using url rewriting with asp.net project having Ajax on page. but on post back when I am checking value of ScriptManager1.IsInAsyncPostBack and Page.IsPostBack its always false. After detail analysis I found that all values stored in ViewState lost during postback.
Code in Global.asax
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
        'MsgBox(Request.ServerVariables("HTTP_HOST"))
        Dim CurrentURL_Path As String = Request.Path.ToLower
        If CurrentURL_Path.ToLower.Contains("/banner/") = True Then
            Dim mycontext As HttpContext = HttpContext.Current
            mycontext.RewritePath(Request.ApplicationPath.TrimEnd("/") & "/Image.aspx?Banner=" & CurrentURL_Path.Substring(CurrentURL_Path.LastIndexOf("/") + 1))
        ElseIf CurrentURL_Path.ToLower.Contains("/image/") = True Then
            Dim mycontext As HttpContext = HttpContext.Current
            mycontext.RewritePath(Request.ApplicationPath.TrimEnd("/") & "/Image.aspx?Image=" & CurrentURL_Path.Substring(CurrentURL_Path.LastIndexOf("/") + 1))
        ElseIf CurrentURL_Path.ToLower.Contains("/logo/") = True Then
            Dim mycontext As HttpContext = HttpContext.Current
            mycontext.RewritePath(Request.ApplicationPath.TrimEnd("/") & "/Image.aspx?Logo=" & CurrentURL_Path.Substring(CurrentURL_Path.LastIndexOf("/") + 1))
        ElseIf CurrentURL_Path.ToLower.Contains("/cat-") = True Then
            Dim mycontext As HttpContext = HttpContext.Current
            mycontext.RewritePath(Request.ApplicationPath.TrimEnd("/") & "/Default.aspx?CategoryId=" & CurrentURL_Path.Substring(CurrentURL_Path.LastIndexOf("-") + 1))
        ElseIf CurrentURL_Path.ToLower.EndsWith("sitemap.xml") Then
            Dim mycontext As HttpContext = HttpContext.Current
            mycontext.RewritePath(Request.ApplicationPath.TrimEnd("/") & "/Sitemap.aspx")
        End If
    End Sub
 

Code in Default.aspx.vb
If Page.IsPostBack = False Then
 
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId And b.CategoryId='" & Replace(Request.QueryString("CategoryId"), "'", "''") & "'")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataSource = pgList
                DataList1.DataBind()
            Else
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                DataList1.DataSource = pgList
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataBind()
            End If
            conn.CloseConn()
            conn1.CloseConn()
        End If
    End Sub
 

    Private Property CurrentPage As Integer
        Get
            Dim objPage As Object = ViewState("_CurrentPage")
            Dim _CurrentPage As Integer = 0
            If (objPage Is Nothing) Then
                _CurrentPage = 0
            Else
                _CurrentPage = CType(objPage, Integer)
            End If
            Return _CurrentPage
        End Get
        Set(value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property
 

    Private Sub butPrevious_Click(sender As Object, e As System.EventArgs) Handles butPrevious.Click
        If ScriptManager1.IsInAsyncPostBack = True Then
            CurrentPage = CurrentPage - 1
            If Request.QueryString("CategoryId") <> vbNullString Then
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId And b.CategoryId='" & Replace(Request.QueryString("CategoryId"), "'", "''") & "'")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataSource = pgList
                DataList1.DataBind()
            Else
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                DataList1.DataSource = pgList
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataBind()
            End If
        End If
    End Sub
 
    Private Sub butNext_Click(sender As Object, e As System.EventArgs) Handles butNext.Click
        If ScriptManager1.IsInAsyncPostBack = True Then
            CurrentPage = CurrentPage + 1
            If Request.QueryString("CategoryId") <> vbNullString Then
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId And b.CategoryId='" & Replace(Request.QueryString("CategoryId"), "'", "''") & "'")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataSource = pgList
                DataList1.DataBind()
            Else
                dt = conn.retriveDataTable("Select a.ProductId,ProductCode,ProductName,'prod-' + Replace(CategoryName,' ','-') + '-' + Replace(ProductName,' ','-') + '-' + Cast(a.ProductId As Varchar(20)) As Url,Price,Images From ProductMaster a,CategoryMaster b,GetFirstImageProductWise c where a.ProductId=c.ProductId and a.CategoryId=b.CategoryId")
                Dim pgList As New PagedDataSource
                pgList.AllowPaging = True
                pgList.PageSize = 12
                pgList.DataSource = dt.DefaultView
                DataList1.DataSource = pgList
                pgList.CurrentPageIndex = CurrentPage
                If pgList.IsFirstPage Then
                    butPrevious.CssClass = "jp-previous jp-disabled"
                    butPrevious.Enabled = False
                Else
                    butPrevious.CssClass = "jp-previous"
                    butPrevious.Enabled = True
                End If
                If pgList.IsLastPage Then
                    butNext.CssClass = "jp-next jp-disabled"
                    butNext.Enabled = False
                Else
                    butNext.CssClass = "jp-next"
                    butNext.Enabled = True
                End If
                DataList1.DataBind()
            End If
        End If
    End Sub
 
    Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        form1.Action = Request.RawUrl
    End Sub
 
I had tried solution provided in below url but not working for me.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

If anyone understand what problem exist in my code please let me know.
Thanks in advance
Posted 26-Mar-13 19:39pm
Edited 27-Mar-13 7:01am
(no name)499K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100