Objective here is to create a Modal Disclaimer when user tries to edit his details in his MySite.
For this on the detials page a modal disclaimer will appear before users start editing/modifying their profile information they must acknowledge a “disclaimer” telling them about the ramifications of what it is they are doing. This disclaimer should be a modal dialog, i.e. they must read it and click it away.
Constraint :
Cannot touch the OOB EditProfile Page i.e cannot write any java script in the OOB page.
Solution : We have to embed javascript in the editprofile page..each time when the page loads and it should be displayed when the page loads and then modal pop window should come on top of the page…
For this we wrote one HTTP module which checks the URL of the current requested page and then takes the reference of Content Place holder main and then add javascript inside that place holder as control..
Since this modal pop window should fire when the loading of the page completes i.e javascript should fire with some differ..so for this we used ScriptLink link control :
Code for HTTP module
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpContext currentContext = HttpContext.Current;
Page page = currentContext.CurrentHandler as Page;
if (page != null)
{
page.LoadComplete += new EventHandler(page_LoadComplete);
}
}
Code snippet for adding the control to the page
void page_LoadComplete(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
//Checking if the current requested page is the EditProfile page of the My Site then only proceed.
if (HttpContext.Current.Request.Url.AbsolutePath.ToString().Trim().ToUpper(System.Globalization.CultureInfo.InvariantCulture).Contains("/_LAYOUTS/EDITPROFILE.ASPX"))
{
//Get the PlaceHolderMain content place holder from the application master page
//to add the Script link control in the page
Control c = page.FindControl<ContentPlaceHolder>("PlaceHolderMain");
if (c != null)
{
ScriptLink link = new ScriptLink();
link.Defer = true;
link.Localizable = false;
//This is the .js file to open the ModalDialog box when user goes to EditProfile page
//this is the java script file which contains the code for the modal pop window
link.Name = "MyFolder/MySiteModalWindow.js";
c.Controls.Add(link);
}
else
{
//Since control object is null so don't insert ScriptLink control in the page
}
}
}
else
{
//Do not inject any script in the page
}
}
This way we can embed java script in to the page through Http module without touching the OOB page.
Enjoy!!!
No comments:
Post a Comment