how to Get PostBack details just before PostBack?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshalika
    New Member
    • Apr 2009
    • 17

    how to Get PostBack details just before PostBack?

    it's important for me to check something before postback. there are several postback controls on the page. is there any way to get postback details(url) before the page go into it?

    thanks
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Request object had enough information about the request to your page.

    Try this:
    protected void Page_Load(objec t sender, EventArgs e)
    {
    Response.Write( this.Request.Ur l.AbsoluteUri);
    }

    Comment

    • akshalika
      New Member
      • Apr 2009
      • 17

      #3
      No. what i want is. when postback happen in a page(because of button click or dropdown selection) which cause to navigate that page to another page(Response.R edirect...). I want to get Redirect URL before leave from first page and prevent redirect some restricted pages.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Have you ever looked into the ASP.NET Page Life Cycle?

        Basically what happens is:
        • A Page request is made for your aspx page
        • Your page is initialized and your controls are loaded as Objects in memory
        • The Page Load event is executed
        • PostBack events are executed
        • The page is rendered and sent to the browser
        • The page is unloaded and all Objects used are destroyed


        This means that if you want to check something before any postback events are executed you should do so in the Page Load event.

        Once you've checked whatever you need to check you can determine what happens during the Postback event.

        For example, say you want to check if the user has permissions to be redirected to another page...you would do this in the page load event:

        VB.NET code:
        Code:
        Dim premittedToBeRedirected As Boolean = False
        
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
           If (HasPermissionsToBeRedirected() = True) Then
              premittedToBeRedirected = True
           End If
        End Sub
        
        Private Sub RedirectingLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RedirectingLinkButton.Click
            If premittedToBeRedirected = True Then
                 Response.Redirect(url)
            End If
        End Sub
        
        Private Function HasPermissionsToBeRedirected() As Boolean
           'This method checks if the person has permission to be redirected
        End Sub
        C# code:
        Code:
        boolean premittedToBeRedirected  = False;
        
        protected void Page_Load(Object sender, System.EventArgs e) 
        {
           If (HasPermissionsToBeRedirected() == true) 
           {
              premittedToBeRedirected = true;
            }
        }
        
        private void RedirectingLinkButton_Click(Object sender, System.EventArgs e ) 
        {
            If(premittedToBeRedirected == true)
            {
                 Response.Redirect(url)
            }
        }
        
        Private boolean HasPermissionsToBeRedirected()
        {
           //This method checks if the person has permission to be redirected
        }

        Comment

        Working...