效果如下
在Onload方法注册事件
protected override void onl oad(EventArgs e)
{
try
{
base.OnLoad(e);
SearchBtn.Click += new EventHandler(SearchBtn_Click);
TranslateDetails.RowSelected += new JQGridEventHandler(TranslateDetails_SelectChanged);
if (SEMI.AppCode.UIUtility.IsPopupClose(this))
{
// 弹出层关闭的监听事件
OnPopupClose();
}
if (!Page.IsPostBack)
{
// 实例化参数
AddDataTranslateLabelMember();
EditBtn.Visible = false;
if (TranslateDetails != null)
{
GetTranslateDetailsList();
}
}
}
catch (Exception ex)
{
Page.StatusBar.WriteError(ex.Message.ToString());
}
}
实例化需要传递的参数(父子VP的控件值联动回显)
private void AddDataTranslateLabelMember()
{
int intConfiguredDataMemberCount = 0;
if (Page.DataContract != null)
{
if (Page.DataContract.DataMembers != null)
intConfiguredDataMemberCount = Page.DataContract.DataMembers.Length;
}
else
Page.DataContract = new UIComponentDataContract();
// manually add the dataContractMember since the custom control's property does not show up at design time
UIComponentDataMember[] objPageDataMembers = new UIComponentDataMember[intConfiguredDataMemberCount + 1];
int intDMIndex = 0;
if (Page.DataContract.DataMembers != null)
{
foreach (UIComponentDataMember objDM in Page.DataContract.DataMembers)
{
objPageDataMembers[intDMIndex] = new UIComponentDataMember();
objPageDataMembers[intDMIndex] = objDM;
intDMIndex++;
}
}
// 实例化参数
objPageDataMembers[intDMIndex] = new UIComponentDataMember();
// VP上绑定的控件的Name,BlankWP_是Webpart的Name
objPageDataMembers[intDMIndex].Key = "BlankWP_.ReturnValue";
// 自定义的参数名称
objPageDataMembers[intDMIndex].Name = "ReturnVallueText";
objPageDataMembers[intDMIndex].ConnectionType = DataMemberConnectionType.Control;
objPageDataMembers[intDMIndex].Property = "Data";
Page.DataContract.DataMembers = objPageDataMembers;
}
按钮事件的注册
public override void WebPartCustomAction(object sender, Personalization.CustomActionEventArgs e)
{
base.WebPartCustomAction(sender, e);
var action = e.Action as CustomAction;
if (action != null)
{
switch (action.Parameters)
{
case "TranslateEditPopup":
{
// 点击按钮执行的方法
TranslateEditPopup();
break;
}
}
}
}
弹出按钮的逻辑
public virtual void TranslateEditPopup(bool EndResponse = false)
{
try
{
Camstar.WebPortal.Personalization.FloatPageOpenAction objAction = new FloatPageOpenAction();
// 传值
Page.PortalContext.DataContract.SetValueByName("LabelId", GetSelectedTranslateInfo());
// 弹出VP的名称
objAction.PageName = "TranslateEditPopupVP";
objAction.FrameLocation = new UIFloatingPageLocation();
// 传值的链接
UIComponentDataContractReturnLink[] objReturnLinks = new UIComponentDataContractReturnLink[1];
objReturnLinks[0] = new UIComponentDataContractReturnLink();
// 参数传递的目标 用于子页面接收值的Name
objReturnLinks[0].SourceMember = "EditPopupLabelText";
// 参数值的来源Name
objReturnLinks[0].TargetMember = "ReturnVallueText";
objAction.DataContractReturnMap = new UIComponentDataContractReturnMap();
objAction.DataContractReturnMap.ReturnLinks = objReturnLinks;
objAction.FrameLocation.Width = 500;
objAction.FrameLocation.Height = 600;
objAction.EndResponse = false;
this.Page.ActionDispatcher.ExecuteAction(objAction);
}
catch (Exception ex)
{
Page.StatusBar.WriteError(ex.Message.ToString());
}
}
子页面取值
protected override void onl oad(EventArgs e)
{
try
{
base.OnLoad(e);
// 取值
string labelId = Page.PortalContext.DataContract.GetValueByName<string>("LabelId");
LabelId.Data = labelId;
if (!Page.IsPostBack)
{
if (labelId != null)
{
GetTranslateLabelByLabelId(labelId);
}
}
}
catch (Exception ex)
{
Page.StatusBar.WriteError(ex.Message.ToString());
}
}