Hello everyone, I am trying to improve my web application performance. So here is the scenario:
I have a product details aspx page and I want users to be able to save the listing to watchlist. I created a hyperlink to navigate the user to Save.aspx page and on page load, I execute the code to add the listing to the database and redirect the user back
the product details page.
It's working fine. But one known problem is that it is not possible for the user to click back button cause it will take them to Save.aspx page and then redirect back again.
I have read some article talking about generic handler(.ashx), which I can avoid a whole page life circle. Is it possible to use it to achieve what I am trying to do here? If you have a better option, please kindly share with me too.
Just prior to your Redirect - you could force the Cache to expire, which would not allow the user to access the Save.aspx from the back button :
//Removes cache to prevent back button access to Save page.
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Navigates to the Details Page
Response.Redirect("DetailsPage.aspx");
As a result the back button doesn't work properly either. I have to click back button twice to get back to the referral page. I can open another thread to ask about this, but if you can help me corret this I appreciate that a lot.
In general, it is never really a good idea to block the user's back button functionality so I am wondering if that is the best route to take. However with regards to your issue with the window.location.hash, you can use a hash within your Redirect :
why implement the save.aspx code in a PageMethod or Webservice and call from the link on details.aspx. Thi way you never go to save.aspx, so if the user presses back they go back to main.aspx:
HTML:
<asp:LinkButton ID="lnkAddToList" runat="server" Text="Add to List" OnClientClick="return SaveToList()" />
<Services.WebMethod()> _
Public Shared Function SaveToList(itemid As String, userid As String) As String
Dim result As String = "Item Added!"
Try
'do you db stuff here
Catch ex As Exception
'show error if you want
result = ex.Message.ToString
End Try
Return result
End Function
Please Mark as Answer if You Find Useful!
But don't expect me to do your job!
UstesG, that's what I am trying to figure out. What's the better option to get this work. Just a question about using web service. Can it be a security problem to show the url of the service in the javascript function?
I have tried to implement the button click event before, i.e. on button click, I execute the code on details.aspx and save the listing to the database. But I find it to be annoying sometimes because when the user clicked refresh after the button click, the
popup is asking if I want to submit the action again. Will using web service gives the same popup when users click refresh?
asplearning
Participant
909 Points
952 Posts
What is the best way to implement this scenario?
Jan 14, 2013 09:13 PM|LINK
Hello everyone, I am trying to improve my web application performance. So here is the scenario:
I have a product details aspx page and I want users to be able to save the listing to watchlist. I created a hyperlink to navigate the user to Save.aspx page and on page load, I execute the code to add the listing to the database and redirect the user back the product details page.
It's working fine. But one known problem is that it is not possible for the user to click back button cause it will take them to Save.aspx page and then redirect back again.
I have read some article talking about generic handler(.ashx), which I can avoid a whole page life circle. Is it possible to use it to achieve what I am trying to do here? If you have a better option, please kindly share with me too.
Thank you very much.
Rion William...
All-Star
27656 Points
4574 Posts
Re: What is the best way to implement this scenario?
Jan 14, 2013 09:41 PM|LINK
Just prior to your Redirect - you could force the Cache to expire, which would not allow the user to access the Save.aspx from the back button :
//Removes cache to prevent back button access to Save page. Page.Response.Cache.SetCacheability(HttpCacheability.NoCache); //Navigates to the Details Page Response.Redirect("DetailsPage.aspx");asplearning
Participant
909 Points
952 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 12:12 AM|LINK
Hello Rion, thanks for the reply. Your solution works but I found another problem. I used this javascript to jump to particular position:
$(function () { window.location.hash = '#menu'; });As a result the back button doesn't work properly either. I have to click back button twice to get back to the referral page. I can open another thread to ask about this, but if you can help me corret this I appreciate that a lot.
Regards;
Rion William...
All-Star
27656 Points
4574 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 12:43 AM|LINK
Is this within the Details page or is this a completely different page altogether?
(I'm just trying to figure out all of the events that are happening so I can gauge what would help you out.)
asplearning
Participant
909 Points
952 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 03:23 AM|LINK
Thanks Rion. The code is on details.aspx page. I have three pages. Let's call them main.aspx, details.aspx, save.aspx. Here is how I navigate:
1. On main.aspx which has all the listings, I clicked on one listing. I was redirect to details.aspx
2. On details.aspx, I clicked on a hyperlink to go to save.aspx
3. On save.aspx, I executed the code to add the listing to a watchlist and redirect back to details.aspx
So now when I clicked back button, I want to directly go to main.aspx.
If you need more clarification, please let me know.
regards;
Rion William...
All-Star
27656 Points
4574 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 03:36 AM|LINK
In general, it is never really a good idea to block the user's back button functionality so I am wondering if that is the best route to take. However with regards to your issue with the window.location.hash, you can use a hash within your Redirect :
Response.Redirect("Details.aspx#menu");UstesG
Contributor
2128 Points
459 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 04:19 AM|LINK
why implement the save.aspx code in a PageMethod or Webservice and call from the link on details.aspx. Thi way you never go to save.aspx, so if the user presses back they go back to main.aspx:
HTML:
JS:
<script type="text/javascript"> function SaveToList() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", url: "WebService.asmx/WebMethodName", data: "{}", success: function (response) { } }); return false; } </script>VB Code Behind:
<Services.WebMethod()> _ Public Shared Function SaveToList(itemid As String, userid As String) As String Dim result As String = "Item Added!" Try 'do you db stuff here Catch ex As Exception 'show error if you want result = ex.Message.ToString End Try Return result End FunctionBut don't expect me to do your job!
Rion William...
All-Star
27656 Points
4574 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 04:21 AM|LINK
Good point UstesG.
Performing a POST and passing your parameters (or form data) to your Save method will allow you to never even travel to Save.aspx.
asplearning
Participant
909 Points
952 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 05:08 AM|LINK
UstesG, that's what I am trying to figure out. What's the better option to get this work. Just a question about using web service. Can it be a security problem to show the url of the service in the javascript function?
I have tried to implement the button click event before, i.e. on button click, I execute the code on details.aspx and save the listing to the database. But I find it to be annoying sometimes because when the user clicked refresh after the button click, the popup is asking if I want to submit the action again. Will using web service gives the same popup when users click refresh?
Thanks for your patient.
Regards;
prasad.magan...
Member
681 Points
214 Posts
Re: What is the best way to implement this scenario?
Jan 15, 2013 06:16 AM|LINK
no, there is no security problem with webservices and on refreshing the page it will not execute code again which depends on ur code.
about the security of the webservices have a look on http://forums.asp.net/t/1507091.aspx/1
Prasad Maganti