browsedisplaymode에서 모드를 편집 모드로 변경합니다
-
10-12-2019 - |
문제
사용자 정의 WebPart가 있습니다. WebPartManager.BrowseDisplayMode
에서 SPControlMode.Edit
로 원 클릭 전환을 수행하려고합니다. 불행히도이 두 가지 매우 다른 모드간에 전환하는 데 직접적인 수단이 없습니다. 그러나 나는 성공적인 과정을 지었을 수도 있지만 행동이 어리석은 일이므로 도움이 필요합니다.
속성이 설정되지 않은 경우 텍스트 "편집"텍스트가있는 링크 버튼이 있습니다. 이 상황은 누군가가 들어오고 페이지에 컨트롤을 삭제 한 다음 나중에 실행을위한 속성을 채우는 경우입니다.
링크 버튼 클릭 이벤트 :
void lbtnViewEdit_Click ( object sender , EventArgs e ) {
if ( WebPartManager.DisplayMode == WebPartManager.BrowseDisplayMode) {
WebPartManager.DisplayMode = WebPartManager.DesignDisplayMode;
//SPContext.Current.FormContext.SetFormMode( SPControlMode.Edit , false );
}
}
.
을 누른 다음 FormContext DisplayMode 설정으로 재생을 시작했습니다. 현재 이벤트 모델로 재생할 때 현재 CreateChildControls()
이벤트에 있습니다.
protected override void CreateChildControls () {
if ( WebPartManager.DisplayMode == WebPartManager.DesignDisplayMode ) {
SPContext.Current.FormContext.SetFormMode( SPControlMode.Edit , false );
}
base.CreateChildControls();
}
.
현재 경험하고있는 동작, 어쩌면 포스트백 행동이지만 확실하지 않습니다.
BrowseDisplayMode
(게시 된 페이지)에서 편집 링크 버튼을 볼 수 있습니다. 그러나 편집 버튼을 클릭하면 SPControlMode.Edit
모드로 이동하려면 두 번 클릭해야합니다. LinkButton의 두 번째 클릭은 내가 들어가고 싶은 디스플레이로 나를 가져옵니다. 그러나 게시 된 페이지보기에서 리본에서 Edit
를 클릭하는 것과 유사한 편집 디스플레이로 한 번의 클릭 전환이되기를 원합니다.
사용하는 프로세스에 대한 도움이 크게 감사 할 것입니다.
해결책 2
Here was my final implementation without using the JavaScript
model to perform the evaluation
if ( WebPartManager.DisplayMode == WebPartManager.BrowseDisplayMode ) {
} else if (WebPartManager.DisplayMode == WebPartManager.DesignDisplayMode) {
}
I do this in my PageLoad, but theoretically you could put this control block anywhere where you need to perform conditional logic based on the current mode the Page/Webpart is in.
Then i overrode some Events:
protected override void CreateChildControls () {
if ( WebPartManager.DisplayMode == WebPartManager.DesignDisplayMode ) {
SPContext.Current.FormContext.SetFormMode( SPControlMode.Edit , false );
}
base.CreateChildControls();
}
protected override void OnPreRender ( EventArgs e ) {
if ( ProviderPart != null ) {
ProviderPart.GetParametersData( new ParametersCallback( SetProviderData ) );
}
base.OnPreRender( e );
}
protected override void OnInit ( EventArgs e ) {
base.OnInit( e );
InitializeControl();
}
다른 팁
There is some extra stuff you need to do if you are on a publishing page. This is the JavaScript code I've had success with in the past doing what you are asking:
function ChangeToEditMode(){
if (window.location.search.match("[?&]PageView=Shared")){
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode == "1")
{
// page is in edit mode
}
}
else{
if (document.forms["aspnetForm"]["MSOLayout_InDesignMode"] != null)
document.forms["aspnetForm"]["MSOLayout_InDesignMode"].value = 1;
if (document.forms["aspnetForm"]["MSOAuthoringConsole_FormContext"] != null)
document.forms["aspnetForm"]["MSOAuthoringConsole_FormContext"].value = 1;
if (document.forms["aspnetForm"]["MSOSPWebPartManager_DisplayModeName"] != null)
document.forms["aspnetForm"]["MSOSPWebPartManager_DisplayModeName"].value = "Design";
ChangeLayoutMode(false);
}
}