473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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
May 25 '09 #1
3 5654
balame2004
142 100+
Request object had enough information about the request to your page.

Try this:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(this.Request.Url.AbsoluteUri);
}
May 25 '09 #2
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.Redirect...). I want to get Redirect URL before leave from first page and prevent redirect some restricted pages.
May 25 '09 #3
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. Dim premittedToBeRedirected As Boolean = False
  2.  
  3. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4.  
  5.    If (HasPermissionsToBeRedirected() = True) Then
  6.       premittedToBeRedirected = True
  7.    End If
  8. End Sub
  9.  
  10. Private Sub RedirectingLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RedirectingLinkButton.Click
  11.     If premittedToBeRedirected = True Then
  12.          Response.Redirect(url)
  13.     End If
  14. End Sub
  15.  
  16. Private Function HasPermissionsToBeRedirected() As Boolean
  17.    'This method checks if the person has permission to be redirected
  18. End Sub
  19.  
C# code:
Expand|Select|Wrap|Line Numbers
  1. boolean premittedToBeRedirected  = False;
  2.  
  3. protected void Page_Load(Object sender, System.EventArgs e) 
  4. {
  5.    If (HasPermissionsToBeRedirected() == true) 
  6.    {
  7.       premittedToBeRedirected = true;
  8.     }
  9. }
  10.  
  11. private void RedirectingLinkButton_Click(Object sender, System.EventArgs e ) 
  12. {
  13.     If(premittedToBeRedirected == true)
  14.     {
  15.          Response.Redirect(url)
  16.     }
  17. }
  18.  
  19. Private boolean HasPermissionsToBeRedirected()
  20. {
  21.    //This method checks if the person has permission to be redirected
  22. }
  23.  
May 25 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt | last post by:
I always see the term "postback" from ASP book, but I am not sure if I fully understand the meaning. Here's my understanding so far, please correct me if any mistakes. Here's a typical html...
6
by: V | last post by:
I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the...
2
by: KathyB | last post by:
Hi, In the pageload of my aspx file I have the following (in both not in postback and is postback)... btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial Numbers',...
0
by: Nathan Truhan | last post by:
All I am writing a Web Form that has a drop-down list that is populated on the First Load from a SQL 2000 Database that contains a list of Terms. Also on the first access (Is Not PostBack) it...
9
by: Joe | last post by:
I have a DataGrid with a templated column that displays ImageButtons. I need to know if one of these buttons caused the postback or just another button on the form. If one of these buttons caused...
21
by: Martin Eyles | last post by:
I am trying to get javascript to cause a page to post back. I have tried calling _doPostBack from my script, but generates an error "object expected". I think this is because the page's script...
5
by: Psych971 | last post by:
Hi, I'm wondering how I can generate a postback using javascript on a page that does not have any controls with the auto-postback property set to true. I know I can just use the submit() function...
10
by: dana lees | last post by:
Hello, I am developing a C# asp.net application. I have a webform which contains 2 dropdowns and a textbox with type="password". On "SelectedIndexChanged" event of the first dropdown, there is...
1
by: mercea | last post by:
Hi guys, I am taking a column from a table and comparing each row in that table with a similar column in a gridview row by row. For each identical answer, grade increments by 1. after all the rows...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.