Hello all
I came across to an situation where user needs to redirect to a "Thank You" or lets say different page when they save item fron "NewForm.aspx" or "EditForm.aspx".
As I do not want to use Visual Studio code that ater save item Event Receiver - "ItemAdded" I tried to look around is there any other option available like Jquery , and yes we can , so easy :)
Here is the code for that.
$(document).ready(function() {
var button = $("input[id$=SaveItem]");
// change redirection behavior
button.removeAttr("onclick");
button.click(function() {
var elementName = $(this).attr("name");
var aspForm = $("form[name=aspnetForm]");
var oldPostbackUrl = aspForm.get(0).action;
var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "custompageurl.aspx");
if (!PreSaveItem()) return false;
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
});
});
Enjoy Jquery!
Disha Shah
I came across to an situation where user needs to redirect to a "Thank You" or lets say different page when they save item fron "NewForm.aspx" or "EditForm.aspx".
As I do not want to use Visual Studio code that ater save item Event Receiver - "ItemAdded" I tried to look around is there any other option available like Jquery , and yes we can , so easy :)
Here is the code for that.
$(document).ready(function() {
var button = $("input[id$=SaveItem]");
// change redirection behavior
button.removeAttr("onclick");
button.click(function() {
var elementName = $(this).attr("name");
var aspForm = $("form[name=aspnetForm]");
var oldPostbackUrl = aspForm.get(0).action;
var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "custompageurl.aspx");
if (!PreSaveItem()) return false;
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
});
});
Enjoy Jquery!
Disha Shah
Disha,
ReplyDeleteCan I use this for the cancel button in 2010 ?
Shannon
good solution!!
DeleteUncaught TypeError: Cannot read property 'action' of undefined
ReplyDeleteHi
ReplyDeleteIt redirects to new page.But it doesnt save the edited value in my case.
Can you please help on this