I have a site which uses Shadowbox-JS to bring up a settings page when a user clicks on a little icon. The settings are there for the user to be able to customise their view of what they're looking at in the main application.
The settings page is a full (but compact) .aspx page which has all the relevant code for the settings to be applied, updated to a database, read from a database etc, so that's all nicely dynamic. What I want is for a postback to occur once the user closes the shadowbox so that the view on the main page automatically updates to reflect their changes.
The following link appears once the user presses 'save' in the settings area:
<a onclick="window.parent.location.href = window.parent.location.href;">Settings saved. Please close this window</a>
This basically just refreshes the whole page and of course, in the process the shadowbox is no more. This approach works fine but the problem is the user also has the option to close the shadowbox by clicking outside of it. I need to capture when this happens and cause a postback (or page refresh) when this happens so that no matter what the settings are always applied when the shadowbox is closed.
I've found the answer, I needed to add an option to the Shadowbox.init() function as follows:
Shadowbox.init({
onClose: function () {
window.location.href = window.location.href;
}
});
Related
I am trying to implement a like counter. That on a click of button increases like count by one in the database and then I am changing its text to "unlike" after clicking again my value is decrementing by 1 in the database too. It all works fine untill the page is posted back.
For eg. If a user clicks like button then text of that button changes to unlike. But if the user reloads the page then. He again gets the button as "like" but not "unlike" is there anyway I can save the state even after postback in asp.net.
Thanks in advance.
You will need to store the 'like' state in a session variable if you want it available between page switches/reloads.
This might help:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e43755ba-49f1-49b9-aa68-448ecf033a62/how-do-you-store-session-variable-in-c?forum=csharpgeneral
Alternatively, get the 'like' state from the database when generating the page.
If you're still experiencing issues, your browser might be caching the page.
If you are on to Javascript, you can try SessionStorage to hold values between page refreshes. It lasts only within the lifetime of a browsers tab and automatically destroyed when the tab/ browser is closed. Values remain completely on the client side and managed by the browser.
Session Storage (W3Schools)
Ex (extracted from the above website):
// Store
sessionStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = sessionStorage.getItem("lastname");
Currently I'm in say Page A. The URL is http://localhost:22507/PageA.aspx. From there select a dropdown value. Now the same page shows some extra data and an edit button along with the dropdown. Page URL is still http://localhost:22507/PageA.aspx. When I click the Edit button its redirected to another page Page B. And the present URL is http://localhost:22507/PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=
While clicking the Back button in the Page B, it directly goes to the first state. ie, I've to again select the drop down, click edit etc.
How can I go back to the just previous state(Page A with data and Edit button) after clicking Back button?
Now I use Response.Redirect("PageA.aspx", false); for redirecting
When changing the selected list item, use pushState to update the browser address bar and history to record the change of state. E.g instead of the address bar still displaying /PageA.aspx, it could instead show /PageA.aspx?selected=1.
If you then use the back button from PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=, pressing back will return you to PageA.aspx?selected=1. You can then parse the query string to determine the correct state to display.
Mozilla provides documentation on pushState here: https://developer.mozilla.org/en-US/docs/Web/API/History_API.
Note that for older browsers there are some compatibility issues. A clunky old method that would work would be to reload the page with a query string when the dropdown is changed, allowing the back button to work in much the same way. An alternative that avoids reloading the page may be to update a cookie with a flag indicating the state. On loading the page, check for the cookie and flag. However, then you would need to consider expiry of the cookie (ie what if they didn't press back but instead navigated to pageA again through some other means, would loading the saved state still be acceptable?).
At my company we are discussing wether or not to got and make our next web app in MVC.
I have been charged to figure out some basic stuff which could stop us dead in our tracks, and so have spend some time figureing out the MVC platform as best i could.
There is however one thing im wondering, is it possible, and if so how - to have a menu made on the _LayOut page/controller, which when a user presses a menu navigation i am able to catch on the specfic page before it goes to the layout controller?
UPDATED I forgot to mention that i want to be able to save a form depending on what site i am on. So i may have 10 pages with different forms and depending on which one of these i am on, i have to save the form on that page using the same link in my menu.
My explaning might be abit off so ill quickly describe the scenario and maybe there is another way of doing this.
The user is filling out alot of data on the page, they then press the navigation menu to go to a new page, i want to save the entered data before navigating to the next page for them.
Sorry for my bad english it is not my primary language.
Thanks in advance for any help.
A way to do what you're looking for is to attach a client-side event handler which submits the data before navigating to a new page. It would look something like this:
$(".navigation a").click(function (event) {
// Get form data, process it and POST/PUT/DELETE
});
If you're supporting modern browsers then you can subscribe to the input event of your form and attach yourself on the before unload if anything in your form has changed since the window was loaded as suggested in one of the comments. If you need to support older browsers as well subscribe to the change event of the input fields in the form in order to attach the handler for beforeunload.
form.oninput = function () {
window.onbeforeunload = submitFormData;
};
function submitFormData() {
// Gather and submit your data
}
I've something that I can't get myself understand. I'm making an app with databound template. I put a textbox on mainpage and a button. when i type something in textbox and press on button it navigates to the listing page and that content comes from web and then if i press on back button and make a new search the results from previous search stays there. how can i reset/clear or disable cache of that page?
It would be helpful if you could post your XAML and code-behind, but I will attempt to make a jab at an answer. Where are you referencing the call to get the data from the web? If it is in the constructor of the page, then that is why the previous search stays there. What is probably happening is the first search constructs the secondary page, does your web call, and binds your data to the page. Then when you press the back button, and click it again, the page is already constructed, so it uses the same data.
It is probably wise to call your web service in the OnNavigatedTo override method. From the first page, you can pass parameters to your secondary page (i.e., pass the search term, then pass the search term into your web service).
Here is an example of passing parameters between pages: http://developer.nokia.com/Community/Wiki/Passing_parameters_while_navigating_between_pages_on_Windows_Phone
Also, make sure your Data Context for the second page is appropriately set each time the page is navigated to, since you have a data bound application.
Without code, I can't really help other than giving these things to think about.
I have to fix one issue in our application that, If child window is opened and user clicks on Browser back button i need to redirect to page asking username and password.
we have 400 aspx pages so just i need to modify in master page. I have code like below
function initPage(){
checkback();
}
This function is written in external javascript file and used in Master Page.
checkback function contains code like below
if (document.forms[0].cprotection.value=='1')
{
document.forms[0].pagecode.value=0;
document.forms[0].act.value='backpressed';
document.forms[0].submit()
}
The above code is working fine for parent window but not if i open child window.
backpressed is keyword am using to check in class file to redirect to page asking username and password. Please help me out in fixing this issue. Thanks in advance
You could add a variable to the session when the child window is loaded and if the user clicks back you would check the session to see if the variable that the child window added to session is nothing inside whichever pages load function and if it is then load normally, if its not redirect to the login page.