While working on a legacy ASP.NET WebForms application I stumbled into the following error: "specified argument was out of the range of valid values. parameter name index". I have a Tabcontainer with gridview filled with users fullnames and 2 ButtonField (edit & View). when I click on View with RowCommand, 5 more tabs get generated with all user information from AD. Everything works fine until I go back to the user tab and click on another user name. How can make my page remove the new 5 tabs created for the first user and add 5 new ones for the new user ? thank you
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajax:ToolkitScriptManager><ajax:TabContainer ID="TabContainer1" OnInit="TabContainer1_Init" runat="server" ActiveTabIndex = "0" ScrollBars="Vertical"><ajax:TabPanel runat="server" HeaderText="Users" ID="TabPanel1"><ContentTemplate><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width= "850px" Height = "650px" onrowcommand = "GridView1_RowCommand" ><Columns><asp:BoundField DataField="name" HeaderText="Name"/><asp:BoundField DataField="SamAccountName" HeaderText="Username" /><asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" /><asp:ButtonField CommandName = "View" ImageUrl ="~/Resources/Images/view.gif" ButtonType = "Image"/><asp:ButtonField CommandName = "Edit" ImageUrl ="~/Resources/Images/edit.gif" ButtonType = "Image"/></Columns></asp:GridView><Triggers><asp:AsyncPostBackTrigger ControlID="TabContainer1" EventName="ActiveTabChanged" /></Triggers></ContentTemplate> </ajax:TabPanel></ajax:TabContainer>
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
mydata();
}
}
public void mydata()
{
t = Regex.Replace(ldap, @"CN=[^,]*,* *", "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
try
{
List<string> allUsers = new List<string>();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "IDEA.COM", t);
UserPrincipal usr = new UserPrincipal(ctx);
// Create a PrincipalSearcher object.
PrincipalSearcher ps = new PrincipalSearcher(usr);
PrincipalSearchResult<Principal> fr = ps.FindAll();
GridView1.DataSource = fr;
GridView1.DataBind();
}
catch (Exception ex)
{
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int row = int.Parse(e.CommandArgument.ToString());
item = GridView1.Rows[row].Cells[1].Text;
var username = GridView1.Rows[row].Cells[0].Text;
string firstname = username.Remove(username.IndexOf("."));
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://idea.com";
DirectorySearcher objADSearcher = new DirectorySearcher(de);
de.AuthenticationType = AuthenticationTypes.Secure;
objADSearcher.SearchRoot = de;
objADSearcher.Filter = "(SAMAccountName=" + item + ")";
SearchResult results = objADSearcher.FindOne();
if (e.CommandName == "View")
{ if (results.ToString() != "") {int flags = Convert.ToInt32(results.Properties["userAccountControl"][0].ToString());
if (Convert.ToBoolean(flags & 0x0002)){Response.Write("<script> alert ('" + "Account Disabled for more then 90 days" + "') </script>");
else
{WindowsIdentity wi = new WindowsIdentity(item);
foreach (IdentityReference group in wi.Groups)
{
try
{
result1.Add(group.Translate(typeof(NTAccount)).ToString());
result1.Sort();
}
catch (Exception ex) { }
}
string tabid;
AjaxControlToolkit.TabPanel apptab = new AjaxControlToolkit.TabPanel();
apptab.HeaderText = firstname + " " + "Application";
apptab.ID = string.Format("Tab{0}{1}",suffix, "tab1");
AjaxControlToolkit.TabPanel sharedtab = new AjaxControlToolkit.TabPanel();
sharedtab.HeaderText = firstname + " " + "SharedCommon";
sharedtab.ID = string .Format ("Tab{0}{1}",suffix ,"tab2" );
AjaxControlToolkit.TabPanel grouptab = new AjaxControlToolkit.TabPanel();
grouptab.HeaderText = firstname + " " + "Internet/RAS";
grouptab.ID = string.Format("Tab{0}{1}",suffix, "tab3");
AjaxControlToolkit.TabPanel idtab = new AjaxControlToolkit.TabPanel();
idtab.HeaderText = firstname + " " + "Info";
idtab.ID = string.Format("Tab{0}{1}",suffix, "tab4");
TabContainer1.Tabs.Add(grouptab);
TabContainer1.Tabs.Add(apptab);
TabContainer1.Tabs.Add(sharedtab);
TabContainer1.Tabs.Add(idtab);
}}}