I have an aspx page with repeater control on it used for showing the data.The user can modify the data inside the repeater but the data will not get saved until the SAVE button is hit. I also have an UNDO button on the page. If the user clicks this button, I want to reload the page and discard the changes made by user (similar to UNDO functionality in MS Office) I need to show him the same data that was shown when the page was loaded for the first time.
Kindly help me with this.
Thank you !
This line of code is read the url as it is, and redirect you to the same page with out new post. Place it on button click, on code behind.
Response.Redirect(Request.RawUrl);
P.S. If you just make post, the input controls will keep their data, so you need to reload the page from the beginning, with the redirect. If you not make redirect you need to handle the controls and clear them.
Additional you can avoid the post back and round trip to the server and do the same on client side with javascript calling the OnClientClick="return ReloadPage();"
with javascript code:
function ReloadPage()
{
top.location.replace( updateURLParameter(document.location.href, "_rnd", Math.random()) );
return false;
}
//
// this function is an improved version of
// http://stackoverflow.com/a/10997390/159270
//
function updateURLParameter(url, param, paramVal)
{
var TheAncor = null;
var newAdditionalURL = "";
var tempArray = url.split("?");
var baseURL = tempArray[0];
var additionalURL = tempArray[1];
var temp = "";
if (additionalURL)
{
var tmpAncor = additionalURL.split("#");
var TheParams = tmpAncor[0];
TheAncor = tmpAncor[1];
if(TheAncor)
additionalURL = TheParams;
tempArray = additionalURL.split("&");
for (i=0; i<tempArray.length; i++)
{
if(tempArray[i].split('=')[0] != param)
{
newAdditionalURL += temp + tempArray[i];
temp = "&";
}
}
}
else
{
var tmpAncor = baseURL.split("#");
var TheParams = tmpAncor[0];
TheAncor = tmpAncor[1];
if(TheParams)
baseURL = TheParams;
}
if(TheAncor)
paramVal += "#" + TheAncor;
var rows_txt = temp + "" + param + "=" + paramVal;
return baseURL + "?" + newAdditionalURL + rows_txt;
}
The above code is adding a random number to the end of the url, or update it if exist to avoid to keep the page on cache. If you all ready avoid to keep the page on cache you can do the same with out the extra random parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With