我需要将从AD查询生成的字符串列表加载到Web userControl中,但它不起作用。当我点击查看按钮时,页面会刷新,没有别的。这是我的代码:
Default.aspx的
if (e.CommandName == "View")
{
WindowsIdentity wi = new WindowsIdentity(item);
foreach (IdentityReference group in wi.Groups)
{
try
{
result1.Add(group.Translate(typeof(NTAccount)).ToString());
result1.Sort();
}
catch (Exception ex)
{ }
}
View f2 = new View(result1);
Session["newResult"] = result1;
Page.LoadControl("~/View.ascx");
}
public List<string> NewResult
{
get
{
if (Session["NewResult"] == null)
{
Session["NewResult"] = new List<string>();
}
return (List<string>)Session["NewResult"];
}
set { Session["NewResult"] = value; }
}
UserControl View.ascx
Namespace Rap.Web
{
public partial class View : System.Web.UI.UserControl
{
public View()
{}
public View(List<string> NewresultFromQuery)
{
NewresultFromQuery = (List<string>)Session["newResult"];//NullReference error
}
protected void Page_Load(object sender, EventArgs e)
{
//create tabs from List<strings>
}
}
}
View.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="Rap.Web.View" %>
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"
</ajax:ToolkitScriptManager>
<ajax:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1"
Width="1016px">
</ajax:TabContainer>
MyUserApp.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyUserApp.aspx.cs" Inherits="Rap.Web.MyUserApp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<%@ Reference Control="View.ascx" %>
答案 0 :(得分:0)
如果您希望数据在回发之间保持不变,则需要将列表存储在会话中。
因此,无论何时添加或删除列表中的数据,都要从会话中获取当前列表NewresultsFromQuery
然后当您更新Session["newResult"] = NewresultsFromQuery
时将其重新放入会话
{{1}}