Custom redirect after creating a new Sharepoint Item
来源:互联网 发布:按键精灵 链接数据库 编辑:程序博客网 时间:2024/04/30 02:55
When creating a new Item in a Sharepoint list, the redirection works according to these rules:
- If the URL contains a valid “Source” parameter, the user user will be redirected to this URL
- Otherwise the user will be redirected to the default view of the list, such as AllItems.aspx
There are different approaches to change this behavior:
Via URL Parameter
One appraoch is to override the redirection by changing the Source parameter of the URL. This means the incoming link to the NewForm.aspx contains the redirection URL already. This is pretty static, sometimes you want to set the redirection on the fly. Also the appraoch enforces the same redirection for both Safe and Close buttons on the form.
Via Event Receiver
It is possible to redirect within an event receiver. This means placing a redirect command within a synchrounous event which aborts the normal event flow in a way, that asynchrounous events and other attached event receivers won’t work anymore.
Via Custom Safe Buttons
It is possible to replace the default buttons on the NewForm.aspx page by custom controls. So basically you develop a custom button that inherits from the Sharepoint “SaveButton” class. In there you can apply custom logic for redirection.
Via JavaScript
This is a novel approach I developed to get more flexibility and stability for the redirection behavior. It allows to set the redirection on the clientside.
$(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,
"MyRedirectionDestination.aspx"
);
if
(!PreSaveItem())
return
false
;
WebForm_DoPostBackWithOptions(
new
WebForm_PostBackOptions(elementName,
""
,
true
,
""
, newPostbackUrl,
false
,
true
));
});
});
So basically we modify the click behavior of the create button on the NewForm.aspx to pass in a new “Source” parameter value just before the form is submitted.
- Custom redirect after creating a new Sharepoint Item
- Creating a Custom SharePoint 2007 List Definition
- Custom redirect after login
- Creating a Custom Login Page for SharePoint 2010
- Custom redirect after login liferay
- Creating a Custom View
- How to redirect to a Custom Page for Event Receiver in SharePoint 2010
- Creating Custom Timer Jobs in Sharepoint
- Creating custom View - Creating a View Class
- Creating a custom data descriptor
- Tutorial: Creating a custom button
- Hack3--Creating a custom ViewGroup
- Creating a New Project
- Creating a new application
- Creating a New ASM Disk Header After Existing One Is Corrupted
- Function not available to this responsibility After Creating and Registering a New Form
- SharePoint 隐藏Add New Item
- SP2010开发和VS2010专家"食谱"--第六章节--Web Services和REST(6)--Creating a custom SharePoint WCF service
- 日本医学博士总结容易早死的十大特征
- c#计算汉语拼音码
- import javax.servlet.annotation.WebServlet
- 配置mongodb分片群集(sharding cluster)
- IOS学习笔记——ViewController生命周期详解
- Custom redirect after creating a new Sharepoint Item
- 外媒关注:大规模的网络攻击让中国网站瘫痪
- Objective-C runtime之消息转发机制(三)
- 思考产品需求十大思维之一
- 认识Arrays.asList方法
- 黑马学习笔记——winform子窗体自适应父窗体大小
- 管理人员的好网址
- hdu/hdoj 1003 Max Sum
- android google app engine