是否可以重新使用SharePoint 2010 Modal对话框?
-
16-10-2019 - |
题
我需要一个简单的“是/否”模式对话框,用于SharePoint Web部件,我真的不想在这里重新发明轮子。 SharePoint为此目的使用了一些非常不错的模态对话框,是否可以重新使用它们,而不是为Showmodaldialog()function创建一个小aspx页面的垃圾
解决方案
实际上,您不必使用dialog.master,因为这本身并不能帮助您使用2010年对话框框架。默认设备的工作正常,因为它的CSS隐藏了您不需要在对话框中不需要的功能区,导航和其他UI组件(...除非您明确说明它们)。
您需要运行一些JavaScript代码来启动对话框(...将进入父页面):
function showModalDialog(title) {
var options = SP.UI.$create_DialogOptions();
options.title = title;
// width and height are optional as the framework autosizes the dialog to the content
options.width = 600;
options.height = 485;
options.url = "/_layouts/htmleditor.aspx";
options.allowMaximize = true;
// you can specify an optional callback
options.dialogReturnValueCallback = Function.createDelegate(null, dialogCallback);
SP.UI.ModalDialog.showModalDialog(options);
}
假设您在对话框页面中具有标准确定和取消按钮(...可以是在VS2010项目中创建的基本SharePoint应用程序页),您只需将这些按钮的事件连接到代码范围内,您就可以发出一些JavaScript以关闭对话框并选择将值重新归因于父页面:
void CancelDialog_Click(object sender, EventArgs e)
{
if (this.IsDialogMode)
// in commonModalDialogClose the zero denotes Cancel and a one denotes OK. The 2nd argument is an optional value to return to the parent page's callback function...assuming one was defined.
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "DismissRecoverPasswordDialog", "window.frameElement.commonModalDialogClose(0, \"\");", true);
else
Response.Redirect(ReferralUrl.Value);
}
希望能有所帮助...请随时提出您遇到的蚂蚁后续问题。
其他提示
是的,您可以重复使用它们。这都是关于使用SharePoint船舶的.Master文件。 Master Page之类的Dialog.Master是为弹出窗口显示的页面而设计的,您应该重复使用它们而不是编写自己的内容。它带有确定和取消按钮和占位符,您可以在其中放置内容。在您的页面中,您必须使用MasterPageFile属性来推荐它们,因为它们不在主页库中。
MasterPageFile="~/_layouts/dialog.master"
在后面的代码中,您可以单击“确定”按钮的代码:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
((DialogMaster)this.Page.Master).OkButton.Click += new EventHandler(this.OkButtonClicked);
}
您可以将OkButton的文本属性更改为“是”,然后取消按钮为“否”,如果您的情况有意义。
重复使用弹出对话框就重复使用而言,您可以使用查询字符串参数来操纵页面上的内容。例如,使用“是/否”按钮,您通常会显示一条消息。您可以将消息存储在资源文件中,并将“查询字符串”中的资源密钥传递到ASPX对话框页面以显示不同的消息。
另外,如果您认为可以重复使用现有的SharePoint对话框,则可以检查其期望的查询字符串参数并发送自己的参数并使用SharePoint的弹出页面。