이것은 similar question입니다. 그러나 거기에 표시된 해결책을 구현하는 데 어려움을 겪고 있습니다. 내 경우동적으로 UserControl을 교환하십시오
나는 두 개의 링크, 사용자 설정, 공간 설정 두 된 UserControls, 즉, UserSettings.ascx
, SpaceSettings.ascx
있습니다. 사용자가 자신이 사용자 설정를 볼 페이지를 방문 처음에
- .
- 두 링크 중 어느 쪽을 클릭했는지에 따라 PlaceHolder은 UserControl을 바꿉니다. 내가 무슨 짓을
는 다음과 같습니다 :이 작동하지 않습니다
public partial class SiteSettings : RefreshDitectedPage {
protected void Page_Load(object sender, EventArgs e) {
}
protected override void OnInit(EventArgs e) {
base.OnInit(e);
string key = Session["Settings"] as String;
System.Diagnostics.Debug.WriteLine(key);
if (key == null) {
Session["Settings"] = "User";
AddUserSettings();
} else {
if (key.Equals("User")) {
AddUserSettings();
} else {
AddSpaceSettings();
}
}
}
protected void SettingsLink_OnCommand(object sender, CommandEventArgs commandEventArgs) {
switch (commandEventArgs.CommandName) {
case "User":
Session["Settings"] = "User";
AddUserSettings();
break;
case "Space":
Session["Settings"] = "Space";
AddSpaceSettings();
break;
}
}
private void AddUserSettings() {
AddSettings(LoadControl("~/UserControls/UserSettings.ascx") as UserSettings);
}
private void AddSpaceSettings() {
AddSettings(LoadControl("~/UserControls/SpaceSettings.ascx") as SpaceSettings);
}
private void AddSettings(UserControl control) {
SettingsPlaceholder.Controls.Clear();
SettingsPlaceholder.Controls.Add(control);
}
/*protected void Page_Unload(object sender, EventArgs e) {
Session["Settings"] = null;
System.Diagnostics.Debug.WriteLine("Unload called");
}*/
}
. 그 결과는 다음과 같습니다 처음에
- 가 세션을 방문 우 ([ "설정"] null로
UserSettings.ascx.cs
의Page_Load
방법은 출력 창에 표시되어에서UserSettings.ascx
가로드 된 UserControl을 (오른쪽) 및 로그). 모두UserSettings.ascx.cs
및SpaceSettings.ascx.cs
의Page_Load
방법에서 - 링크가 클릭 된 공간 설정의 UserControl을
SpaceSettings.ascx
가로드 된 (오른쪽)하지만 출력 창에이 사용자 (잘못된)를 인쇄하고 또한 로그 표시된 (UserSettings.ascx.cs
의 로그가 잘못되었습니다). 또한 두UserSettings.ascx.cs
및SpaceSettings.ascx.cs
의Page_Load
방법에서 로그를 사용자 설정 링크를 클릭되었을 때 - 는 UserControl을
UserSettings.ascx
은로드 된 (오른쪽)하지만 출력 창에이 공간 (잘못된)를 출력한다 표시된 (SpaceSettings.ascx.cs
의 로그가 잘못되었습니다.). - 나는, 말,
SpaceSettings.ascx
의 버튼이 뒷면 클래스 처음에 이벤트를 해고하지 않는 클릭했습니다,하지만 그렇게되면이 그것을 클릭되는 경우 된 UserControls 각각 두 버튼을 추가 두 번째로. 주저 시간은 로깅 사용자 (틀린)과 두 번째 시간 스페이스 (오른쪽) 다음 이벤트가 발생합니다. - 페이지를 두 번째로 방문하면 마지막으로로드 된 컨트롤이 표시됩니다.
Session["Settings"]
이 null이 아니기 때문에.Page_Unload
및OnUnload
메서드에서이 값을 null로 설정하려고 시도했지만 둘 다 작동하지 않습니다.Page_Unload
은 매번 호출되고 있으므로PostBack
과OnUnload
은 전혀 호출되지 않으므로 시스템이 중단됩니다.
내가 대신 Session["Settings"]
의 Request["Settings"]
하지만 Request["Settings"] = "User"
을 사용하려고하고 Request["Settings"] = "Space"
나 시간 오류 컴파일주고있다 :
Property or indexer 'System.Web.HttpRequest.this[string]' cannot be assigned to
가 어떻게이 문제를 해결할 수 있습니까? 감사합니다. ,
다른 사람들이 문제를 해결하는 방법에 대해 의견을 나눌 때까지 기다릴 수도 있지만 그러한 클라이언트 측 탭에 대해 jQuery로 전환 할 시간이 아닙니까? http://docs.jquery.com/UI/Tabs –
@Lex Li이 경우 jQuery 탭을 사용해야하는 이유는 무엇입니까? 그런 다음 페이지로드시 모든 내용을로드해야하며 매우 나쁠 것입니다. –
jQuery 탭도 AJAX를 지원합니다. –