Hi Together
Could someone help me with following issue...
I am Using following MessageBox to display some erroros or success ocurances on the page:
public static void ShowMessage(Page page, string message)
{
message = Regex.Replace(message, @"[^\w\.@-]", "",
RegexOptions.None, TimeSpan.FromSeconds(1.5));
AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(page, page.GetType(), "MessageBox", "alert('" + message + "')", true);
}If some Errors happens in c# methods in code behind after page submit message box is appearing fine.
The Problem is that the message does not appear in case of some error during page loading...
Example:
My web form is loading some user from activeDirectory into greadview..
GetUserPrincipal method is called when page is loading to fill up griedview.
If some error happens in GetUserPrincipal method during loading of the page, my message box, which is integrated in catch part of the method,
does not appear.
What is the Problem...Do you have any idea?
Thanks in advance for your help
Asp Code Part:
<asp:Panel Style="display: none;" ID="UsrPopupPanel1" runat="server"><div id="UsrPopupMainContent" class="PopupMainContent"><div id="UsrPopupToolbox"><asp:TextBox ID="UserName" runat="server"></asp:TextBox><asp:Button ID="SearchUser" CssClass="EditButton" runat="server" Text="Search" OnClick="SearchUser_Click" /></div><div id="DivGridTable"><asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetUserPrincipals" TypeName="UserManagement.AD.AdManagement"
FilterExpression="LastName like '{0}*'" EnableCaching="false"><FilterParameters><asp:ControlParameter Name="LastName" ControlID="UserName" PropertyName="Text" /></FilterParameters></asp:ObjectDataSource><asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
OnRowDataBound="GridView1_RowDataBound" AllowSorting="True" OnSorting="GridView1_Sorting" AutoGenerateColumns="False"><Columns><asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /><asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /><%--<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />--%><asp:BoundField DataField="AccountName" HeaderText="AccountName" SortExpression="AccountName" /></Columns><FooterStyle CssClass="GridFooter" /><HeaderStyle CssClass="GridHeader" /><PagerStyle CssClass="GridPage" /><RowStyle CssClass="GridRaw" /><SelectedRowStyle CssClass="GridSelectedRow" /><SortedAscendingCellStyle CssClass="GridSort" /></asp:GridView><br /></div><asp:Button ID="CloseButton" CssClass="EditButton" runat="server" Text="Close" /><asp:Button ID="OKButton" CssClass="EditButton" runat="server" Text="OK" /></div></asp:Panel><ajaxToolkit:ModalPopupExtender
ID="ModalPopupExtender1"
TargetControlID="btnNewMailboxBrowse"
PopupControlID="UsrPopupPanel1"
OkControlID="OKButton" CancelControlID="CloseButton"
BehaviorID="mpe" runat="server"></ajaxToolkit:ModalPopupExtender></ContentTemplate></asp:UpdatePanel>Method in Code Behind:
public DataTable GetUserPrincipals()
{
DataTable results = new DataTable();
List<string> excludedOUs = new List<string>();
string linkedDomainFqdn = HttpContext.Current.Session["LinkedDomainFQDN"] as string;
string linkedUsersOu = HttpContext.Current.Session["LinkedUsersOU"] as string;
string linkdeLdapAccount = HttpContext.Current.Session["LinkedLdapAccount"] as string;
string linkedLdappassword = PassDecryption.DecryptPassword(HttpContext.Current.Session["LinkedLdapPass"] as string);
using (PrincipalContext principalcontext = new PrincipalContext(ContextType.Domain, linkedDomainFqdn, linkedUsersOu, linkdeLdapAccount, linkedLdappassword))
{
Page page = HttpContext.Current.CurrentHandler as Page;
try
{
UserPrincipal adPrincipal = new UserPrincipal(principalcontext);
adPrincipal.SamAccountName = "*";
PrincipalSearcher principalSearcher = new PrincipalSearcher();
principalSearcher.QueryFilter = adPrincipal;
results.Columns.Add("LastName");
results.Columns.Add("FirstName");
results.Columns.Add("AccountName");
foreach (UserPrincipal p in principalSearcher.FindAll())
{
if (!p.DistinguishedName.Contains("CN=Users"))
{
DataRow dr = results.NewRow();
if (p.Surname != null)
dr["LastName"] = p.Surname;
dr["FirstName"] = p.GivenName;
dr["AccountName"] = p.SamAccountName;
results.Rows.Add(dr);
}
}
//results.AsEnumerable().OrderBy(o => o["LastName"].ToString());
results.DefaultView.Sort = "LastName" + " " + "ASC";
results = results.DefaultView.ToTable();
principalcontext.Dispose();
}
catch (Exception exception)
{
MessageBoxInfo.ShowMessage(page, "Exception caught:" + exception.Message.ToString());
principalcontext.Dispose();
}
finally { principalcontext.Dispose(); }
//return adPrinicpals;
return results;
}
}