I’m using a single page for two different purposes. By default it has one behavior and on coming to same page after redirecting via a link button it has a different behavior, like changing master page, etc…
How can I detect this and change the behavior accordingly?
If you have one page with two different behaviours then I would suggest that you want something like a querystring parameter to differentiate between the two purposes (eg somepage.aspx?mode=changeMaster). You can then check for this value and change your behaviour accordingly.
If you are only every doing the second behaviour from one place then its probably easiest to let it have a default behaviour rather than requiring the mode parameter (so you wouldn’t have to change all your links to the page, just that one linkbutton). This should be much more reliable than relying on referrers and other such things which aren’t always sent.