Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help forcing a postback

Status
Not open for further replies.

theomen

Programmer
Jun 2, 2004
158
GB
I'm currently developing a website which requires customers to login to be able to view certain documents.

My login form is on my master page, and I have a content page which displays a list of documents. If a document is to be viewed by customers only, then the link is disabled until the customer logs in.

The problem I've had is that, because the content page loads before the master, when the customer first logs in the content page isn't updated, so doesn't realise that the customer is now logged in and so the link remains disabled. If I then refresh the page by hitting F5, the link becomes enabled.

I've finally managed to get around this by putting Server.Transfer(Request.ServerVariables["script_name"]) after logging the customer in. However, this then loses any previous postback data, so if I've drilled through a load of categories, I get shoved back to the top-level category.

Is there another way in which I can get the content page to realise that a customer is logged in without having to manually refresh the page, ie. by forcing it to reload with previous form submissions intact?
 
I have also tried doing the following:

Page.RegisterClientScriptBlock("anything", "<script>document.forms[0].submit</script>");

which doesn't seem to do anything much (it seems to run and there is no javascript error but content page still doesn't see the session values I have set until I refresh the page).
 
Override OnPreRender in the content page and set the link's visibility there.

Your login logic probably happens after Load and before PreRender during the "Process PostBack Events" phase:


Thus, you probably have the information you need to determine the link's visibility by PreRender.

MCP, MCTS - .NET Framework 2.0 Web Applications
 
Thanks BoulderBum.

I've just managed to get it working anyway with the previous method. Turns out I did have a javascript error but didn't see it, I'd for some reason changed the javascript from document.forms[0].submit to document.form1.submit, changed it back and it now seems to be working (I say seems, up to now every time I get one thing working it breaks something else, so I might end up using your method anyway).

Thanks again.
 
I'd still recommend trying my method. It's more elegant, better performing, and requires minimal code (only one real line, not counting method definition).

Delivering a page to the client just to post it back immediately may create maintainability and usability problems. What happens if a developer introduces a block of code that runs on PostBack, but doesn't account for the extra PostBack? How will the user feel if they try working with the web page that just got rendered just to see it flicker and go away because of the extra post? Why make the process take even a half second longer because of extra, unnecessary round trips to the server?

MCP, MCTS - .NET Framework 2.0 Web Applications
 
I have now implemented the PreRender method, which is working.

Now just got to stop it wiping my search results.

Thanks again.
 
Good to hear. If you'd like help figuring out how to not wipe out any existing data, please feel free to post further.

MCP, MCTS - .NET Framework 2.0 Web Applications
 
Thanks. I just had to mess around with my method calls, making sure it didn't re-bind the gridview if the user had just logged in for example. It all appears to be working at the moment (I hope).

The product catalogue was more interesting as there were so many different ways in which it has to populate the grid view. For example, the customer could have just selected a different category, or they could have submitted a search, or they could have just arrived at the catalogue from google for example in which case I take the keywords they entered into google and display products based on that.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top