SharePoint 2010 Application Pages and Modal Dialogs the easy way

, , , , ,

The custom 'Edit web info' Application Page displayed in a SharePoint 2010 Modal Dialog.
SharePoint 2010 ships with the new Modal Dialog framework that allows you to display dialog windows in an unobtrusive and user friendly way. This is extremely important when creating user friendly solutions as it allows users to preserve their context while providing some additional information. While the new modal dialog framework is definitely a great idea, there is one thing missing in the implementation: support for communicating with custom application pages.

Custom Application Pages the 2007-way

SharePoint 2007 lacked any kind of support for dynamic User Experience. Standard Application Pages used postback to process information and in order to provide a seamless experience we had to do exactly the same in our custom Application Pages. Every Application Page had some logic attached to it and after completing its work, it redirected the user either to where he came from or to the current Site.

SharePoint 2010 Modal Dialogs

In SharePoint 2010 the situation looks a bit different. SharePoint 2010 ships with the new Modal Dialog framework which allows you to interact with users in an unobtrusive way using just a few lines of JavaScript.

The following JavaScript snippet is sample code that you could use to open a SharePoint page in a modal dialog:

var options = {
  url:'/_layouts/prjsetng.aspx',
  title:'Title, Description, and Icon',
  width:640,
  height:400
}

SP.UI.ModalDialog.showModalDialog(options);

The ‘Title, Description, and Icon’ page opened in a SharePoint 2010 Modal Dialog.

As you can see it’s really easy for us to benefit of the new capabilities in our custom solution. In the background SharePoint automagically removes the Ribbons, menus etc. from the page leaving only the content. This is a great behavior because it allows you to create interfaces that are both suitable for normal view and Modal Dialogs without a lot of extra effort! There is however one ‘however’…

The ‘Site Settings’ page opened in a SharePoint 2010 Modal Dialog.

This is exactly what happens when you click the OK button on the Title, Description, and Icon page. The page will use its default behavior and will redirect to the Site Settings page. In fact most of the standard SharePoint 2010 Application Pages use the ‘old’ behavior.

Custom Application Pages and Modal Dialogs: what’s in the box?

Developing custom Application Pages is a regular part of many SharePoint Solutions. Whether it’s for management purposes or for requesting user input, Application Pages are a great way to interact with users. The Modal Dialog framework in SharePoint 2010 makes it extra interesting since it allows you to use Application Pages in an unobtrusive way. Unfortunately out of the box there is very little standard support for leveraging Modal Dialogs with Application Pages. And although it seems like a really generic functionality, it is something you would have to do yourself for the biggest part. Sounds like a call to action.

Side note on the sample case

To help you better understand the examples in this article I chose to create a custom Application Page similar to the standard ‘Title, Description, and Icon’ page provided with SharePoint. I chose that particular page because it requires you to differently handle closing the Modal Dialog depending on the taken action, which is great for discussing the capabilities available in SharePoint 2010. To make it easier for you to distinguish that I’m talking about the custom page I called it the ‘Edit web info’ page.

Step 1: The Dialog Application Page base class

Support for Modal Dialogs in Application Pages is something generic. As it’s something you will be reusing in all your custom Application Pages it’s a good idea to create a base class that contains all the plumbing that you need to get the job done. You can then create your custom Application Pages and by inheriting from that class you can ensure that you have consistent baseline within the whole solution or even across solutions.

Defining the base class

/// <summary>
/// Modal Dialog-aware Application Page base class.
/// </summary>
public abstract class DialogLayoutsPageBage : LayoutsPageBase
{
    /// <summary>
    /// URL of the page to redirect to when not in Dialog mode.
    /// </summary>
    protected string PageToRedirectOnOK { get; set; }
    /// <summary>
    /// Returns true if the Application Page is displayed in Modal Dialog.
    /// </summary>
    protected bool IsPopUI
    {
        get
        {
            return !String.IsNullOrEmpty(base.Request.QueryString["IsDlg"]);
        }
    }

    /// <summary>
    /// Call after completing custom logic in the Application Page.
    /// Returns the OK response.
    /// </summary>
    protected void EndOperation()
    {
        EndOperation(1);
    }

    /// <summary>
    /// Call after completing custom logic in the Application Page.
    /// </summary>
    /// <param name="result">Result code to pass to the output. Available results: -1 = invalid; 0 = cancel; 1 = OK</param>
    protected void EndOperation(int result)
    {
        EndOperation(result, PageToRedirectOnOK);
    }

    /// <summary>
    /// Call after completing custom logic in the Application Page.
    /// </summary>
    /// <param name="result">Result code to pass to the output. Available results: -1 = invalid; 0 = cancel; 1 = OK</param>
    /// <param name="returnValue">Value to pass to the callback method defined when opening the Modal Dialog.</param>
    protected void EndOperation(int result, string returnValue)
    {
        if (IsPopUI)
        {
            Page.Response.Clear();
            Page.Response.Write(String.Format(CultureInfo.InvariantCulture, "<script type=\"text/javascript\">window.frameElement.commonModalDialogClose({0}, {1});</script>", new object[] { result, String.IsNullOrEmpty(returnValue) ? "null" : String.Format("\"{0}\"", returnValue) }));
            Page.Response.End();
        }
        else
        {
            RedirectOnOK();
        }
    }

    /// <summary>
    /// Redirects to the URL specified in the PageToRedirectOnOK property.
    /// </summary>
    private void RedirectOnOK()
    {
        SPUtility.Redirect(PageToRedirectOnOK ?? SPContext.Current.Web.Url, SPRedirectFlags.UseSource, Context);
    }
}

The above snippet presents a base class for a Modal Dialog-aware Application Page. All the different pieces are explained in XML comments, but probably the best way to understand how things work is to see it in action.

Behind the scenes of a Modal Dialog-aware Application Page

The ‘Edit web info’ custom Application Page.

The following code is the code behind of our custom ‘Edit web info’ page.

public partial class EditWebInfo : DialogLayoutsPageBage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebTitle.Text = Web.Title;
            WebDescription.Text = Web.Description;
            WebName.Text = Web.Name;
        }
    }

    protected void BtnUpdateWeb_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            Web.Title = WebTitle.Text;
            Web.Description = WebDescription.Text;
            bool urlChanged = !String.IsNullOrEmpty(WebName.Text) && !Web.Name.Equals(WebName.Text);
            if (urlChanged)
            {
                string source = Request.QueryString["Source"];
                if (!String.IsNullOrEmpty(source))
                {
                    PageToRedirectOnOK = source.Replace(Web.Name, WebName.Text);
                }

                Web.Name = WebName.Text;
            }

            Web.Update();

            EndOperation(1);
        }
    }
}

As you can see the code is fairly simple. In the Page_Load method we retrieve some values from the current Site and fill the controls on the page with them. In the BtnUpdateWeb_Click event handler we do the opposite: we take the new values and update the current Site with them.

Following the User Experience

Because we want the User Experience to be as good as possible we have a few different cases to handle.

First of all there is the scenario when user either closes the Modal Dialog using the Close button or clicks the Cancel button. In this scenario nothing has changed and we don’t have to do anything. The good news is that is already being handled by SharePoint out of the box and we don’t have to worry about it.

The next scenario is when the user changes the Title and/or the Description of the Site. What we need to do is to save the new values and refresh the Site so that the user can see the values being updated.

The last scenario is when the user changes the URL of the Site. In this case we have to get the URL of the current page, replace the URL part of the Site with the new value and redirect the user to the new URL.

From the Application Page point of view the only difference between the last two cases is the redirection. In the second scenario the value of the PageToRedirectOnOK property is being set to the new URL what allows the base class to redirect the user to the current page but then at changed URL. Finally, we call the simple variant of the EndOperation method with the OK result. If the Application Page has been opened in a Modal Dialog a JavaScript snippet will be sent to the output. This snippet will contain the OK result and depending on the action the new URL of the site.

Step 2: Handling the response on the client-side

Good User Experience around Application Pages consists of two pieces: not only we need to cover correct actions on the server, but also we have to take care that there is as little disruption for the users as possible. In other words: if there is no need to reload the whole page – don’t do it.

Earlier in this article I showed you a simple JavaScript snippet that can be used to open a SharePoint 2010 Modal Dialog. That sample was pretty straight forward and didn’t contain any logic for handling the response from the Application Page. Let’s extend it a little and add some handling routines to it:

var options = {
    url: SP.Utilities.Utility.getLayoutsPageUrl('DialogApplicationPages/EditWebInfo.aspx?Source=' + location.href),
    title: 'Edit web info',
    allowMaximize: false,
    showClose: true,
    width: 800,
    height: 330,
    dialogReturnValueCallback: Function.createDelegate(null, function (result, returnValue) {
        if (result == SP.UI.DialogResult.OK) {
            if (returnValue == null) {
                SP.UI.Notify.addNotification('Operation successful');
                SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
            }
            else {
                location.href = returnValue;
            }
        }
    })
};

SP.UI.ModalDialog.showModalDialog(options);

The general idea is the same: we create a new object with all the options for our dialog and pass it to the SP.UI.ModalDialog.showModalDialog function. The difference is in the dialogReturnValueCallback property that now contains a delegate to the function that will be executed after the Modal Dialog window has been closed.

The delegate function executed after closing a Modal Dialog takes two parameters: result, which is an integer and can have one of the three values: invalid (-1), cancel (0) or OK (1), and returnValue which is an optional value that can contain some data from the Application Page. Getting back to our three scenarios…

In the first scenario, where user clicks the Cancel button, the result parameter will be equal to SP.UI.DialogResult.cancel or 0. So by checking for the value of the result parameter we can ensure that we will execute code only if the Modal Dialog has been closed by clicking the OK button.

In the second scenario, where only the title and/or description of the Site have been changed, the returnValue parameter is empty. In this case we don’t need to reload the whole page. The Modal Dialog framework allows us to quickly refresh the page by calling the SP.UI.ModalDialog.RefreshPage function, which has definitely a better experience than reloading the whole page.

Finally, in the last scenario, where the URL of the Site has been changed, the new URL is passed in the returnValue parameter and we use it to redirect the user to the new URL.

And that’s really it. The above framework provides you with the basic functionality for communicating with Application Pages and passing the results to the JavaScript in the originating page. From here you can easily extend the implementation to fit the specific needs of your application.

Technorati Tags:

79 Responses to “SharePoint 2010 Application Pages and Modal Dialogs the easy way”

  1. Abdul Says:

    In your custom application page code behind, you reference an event handler, BtnUpdateWeb_Click, when is this called -how is it called by te dialog? and is this an event handler to a button on your custom application page – if so, why doesn't the button appear in the modal dialog?

  2. Waldek Mastykarz Says:

    @Abdul: The Event Handler you mentioned is being called after clicking the OK button which is a part of the custom Application Page. If you look carefully at the screenshot of my custom Application Page in a Modal Dialog you'll see that the button is there.

  3. Abdul Says:

    OK – Thanks, Yes, I can see that OK button, but I didnt know it was part of the custom application page, I thought it was there by default on the dialog.

    Thanks for the answer.

    Excellent Post.

  4. Robin Says:

    Hey buddy, tbanks! Will be using this in my current project ;)

  5. Waldek Mastykarz Says:

    @Robin: Awesome, looking forward to the lessons learned/feedback from the field :)

  6. Ronak Says:

    Thanks Waldek for sharing information.
    i am working on Dialog in one of Public facing site i am working on but i am not using application page.will it work on only with application pages ?
    what i am doing is i have created webpart then i created based on page layout and insert webpart in this page and then open this page as Dialog.it works fine but carry branding like header and footer that i don't want

  7. Waldek Mastykarz Says:

    @Ronak: it should work with any kind of pages. You can use the s4-notdlg CSS class to hide all unwanted elements on your page when in dialog mode.

  8. Ronak Says:

    Thanks for reply you are right and i have used that class but its doesn't work and i also know why its not working but can't find solution.
    Somehow HTML code for Dialog doesn't insert class ms-dialog within iframe of HTML class.
    If you have any suggestion then i will appreciate it.

  9. Waldek Mastykarz Says:

    @Ronak: do I understand it correctly that you have a page with an iframe on it, and that the page inside that iframe doesn't get the dialog classes?

  10. Ronak Says:

    Kind of.When you use dialog in Sharepoint 2010 it creates iframe with popup HTML and this html has class called ms-dialog something like this
    Code for Popup dialog within iframe and in my case i dont see ms-dialog class and thats why s4-notdlg is not hiding elements.Here is how s4-notdlg is define .ms-dialog .s4-notdlg {display:none;}.I tired to use other custom class but no luck so far.

  11. Waldek Mastykarz Says:

    @Ronak: ok, so it's not your page that contains the iframe, but you mean actually the modal dialog iframe that hosts your page. Do you have in your master page? Without it SharePoint wouldn't be able to add the ms-dialog class.

  12. Ronak Says:

    Yes.I don't know Understand your question Do you have in your master page?
    but here brief idea what i am doing i have created webpart first and then create a page based on blankwebpartpagelayout and then add webpart in one of zone and then in other page layout i have JS to open this page as model dialog.hope this make it clear….
    Thanks for your time and really appriciate

  13. Waldek Mastykarz Says:

    @Ronak: I thought you mentioned that you created a custom Master Page or are you using an out-of-the-box one?

  14. Ronak Says:

    Waldek i have custom master page

  15. Waldek Mastykarz Says:

    @Ronak: then the question remains: does the tag on the top of your Master Page has the runat="server" attribute?

  16. Ronak Says:

    yes it does have attribute runat="server"

  17. Ronak Says:

    Hi Waldek i can't believe this problem was with Telerik Control that means i can not use telerik control for within dialog.

  18. Waldek Mastykarz Says:

    @Ronak: Have you checked with Telerik if they have an updated version of their control that would work with SP2010?

  19. Ronak Says:

    Hi Waldek i have opened support ticket with them also i am using latest version of Telerik anyway i am trying to get it working with Radwindow Telerik control and i got functionality working now will try to hide elements with custom css class.once i hear from telerik i will update you for future ref.
    Thanks for your time and suggestion

  20. Curtis Says:

    Waldek,

    Thanks for the example. One problem I'm having with the Dialog framework is that there seems to be a default set of OK and Cancel buttons that are autotmatically loaded. This is a problem in that I can only maniupulate them via client-side code, and I can't hide them and use my own buttons on the custom Application Page. I notice in your example you only have one set of OK/Cancel buttons and they appear to be the ones from your custom App Page – how do you do this? I can't get rid of the defualt dialog framework buttons.

    Thanks.

  21. Hakan Aygun Says:

    Hi Waldek,

    Excellent post! Congrats!!!

    Would it be possible to download aspx code of "edit web page"? In this way, It would be much easier to understand the code you have provided.

    All the best,
    Hakan.

  22. Waldek Mastykarz Says:

    @Hakan: I don't think I still have the full solution. However all of the code is included in this post. Do you have any specific questions?

  23. Hakan Aygun Says:

    Hi Waldek,

    I was mentioning ASPX file (the only missing item as far as I can see) to test it immediately. However, I was able to create ASPX file with the same web control IDS and tested it.

    Thanks again for this great post.

    Hakan.

  24. Sharron Clemons Says:

    Hi Waldek i can't believe this problem was with Telerik Control that means i can not use telerik control for within dialog.

  25. rene Says:

    Hi,

    I am new to sharepoint and developing. I am trying to create a hyperlink as a modal dialog but I am having problems.

    Can you help?

    This hyperlinks work great in opening up the modal dialog

    HyperLink link = new HyperLink();
    link.Text = "Read More"; link.NavigateUrl = string.Concat("javascript: ShowDialog('", SPContext.Current.Site.RootWeb.Url,
    "/Lists/", this.Text, "/DispForm.aspx?ID=", item.ID, "\"')"); this.Controls.Add(link);

    I am trying to replace the href below with the hyperlink above but I am having trouble.

    str2 = string.Concat(new object[] { obj2, "", this.FirstWords(this.StripTagsCharArray(item[this.BodyField].ToString()), Convert.ToInt32(this.NumWords)), "… read more" });

  26. Waldek Mastykarz Says:

    @rene: what is exactly the problem that you are experiencing?

  27. Jason Says:

    Great article, I am wondering if this could be adapted to pass values to a form that is loaded into the dialog box. I have a web part page with a links list, a discussion board, and a custom page viewer web part. The links list provides a filter value to the discussion board and the page viewer loads a new page when a link is selected. Everything I have on my page works great, however, when a user clicks on the add new discussion I have no way of pre-populating the column in the discussion board that associates the links list item, my users would have to do that, and I would like automate that tidbit by passing the selectedID. Any tips would be much appreciated!

  28. Waldek Mastykarz Says:

    @Jason: As far as I know, the only way to pass parameters into the dialog would be (client-side) by using a query string parameter or setting a cookie or (server-side) using a session variable.

  29. pakdanan Says:

    Thanks Waldek, Keep up the good work

  30. Waldek Mastykarz Says:

    @pakdanan: thank you, I appreciate it :)

  31. feisal abedeen Says:

    Wow, after reading everything at MSDN about it and still being stuck, your blog saved my day! Works great. Thanks.

  32. Waldek Mastykarz Says:

    @feisal: great I could help :)

  33. GIC Says:

    Thank you very much for sharing this. Really usefull stuff – good work!

  34. rav Says:

    Excellent.. learned something new today!!

  35. Bryce Says:

    Just wondering where the link is to download the code.

  36. Waldek Mastykarz Says:

    @Bryce: there is no separate download. The snippet I included in the article is the code.

  37. Mike Says:

    @Waldec
    A download of the code would be nice, I am spending a ton of time trying to find all the using references that you don't list. The post is great, but I don't have memorized all the references and you didn't include them with your code on the page.

    Thanks for the good post!

  38. Venkat Says:

    Hi waldeK,
    very good post….you had mentioned that the solution was not fully built yet. Was wondering if you have something to share as I was trying this and running into errors.

    Thanks
    Venkat

  39. Waldek Mastykarz Says:

    @Venkat: Which part are your referring to? The code I included is meant as a base for your own solution rather than being a turn-key solution of its own.

  40. Sreekanth Says:

    can u give source code or give step by step methods. I had confusion how to write code.

  41. Waldek Mastykarz Says:

    @Sreekanth: which part don't you understand exactly?

  42. KaLynn Says:

    Hello, I am trying to call some javascript code using showModalDialog directly from our code behind (a user control) to launch the out of box EditForm.aspx. This code is very much like your javascript example. One of the options to the showModalDialog is the url to the EditForm.aspx with dynamic parameters for the appropriate doc library for which to check in the file (the file was uploaded previously in the code behind logic). My method to call the javascript is the Page.ClientScript.RegisterClientScriptBlock. I am getting an error that the DocumentEventHandler assembly could not be loaded. Do you know what I need to do to resolve this?

  43. Waldek Mastykarz Says:

    @KaLynn: not really, but I guess it would have to do something with your code behind rather than modal dialogs.

  44. Sohaib Khan Says:

    Hi Waldek,

    I'm following your logic. Your logic works fine – appreciated. But, I'm facing a small problem.

    In the js file:
    if (result == SP.UI.DialogResult.OK)
    {
    if (returnValue == null)
    { SP.UI.Notify.addNotification('Operation successful'); SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
    }
    else
    {
    location.href = returnValue;
    }
    }

    If returnValue == null then after completing the operation, it disables the buttons on the contextual tab whereas if returnValue !=null then it doesn't disable the buttons.

    Please let me know where i'm going wrong.

    Thanks.

    Sohaib Khan

  45. Waldek Mastykarz Says:

    @Sohaib: Did you copy wrong code sample by any chance?

  46. Sohaib Khan Says:

    @Waldek: Nops.

    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

    The above line disables the contextual tab buttons.

  47. Waldek Mastykarz Says:

    @Sohaib: This could be correct since the page is refreshed. After this line: is your Web Part still selected/active or not anymore?

  48. Sohaib Khan Says:

    After the line, my web part still focused and it shows disabled buttons on contextual tab

  49. Waldek Mastykarz Says:

    @Sohaib: Perhaps refreshing the page causes the Web Part to lose focus internally. Do you need to refresh the page after closing the dialog? If not you could simply remove the line which should solve your issue.

  50. Sohaib Khan Says:

    @Waldek: In my scenario, i select multiple rows from the SPGridView through check boxes which is present in my webpart. Once user selects rows, it automatically enables the contextual tab from where user can press any button for desired operation. When user presses the button, it opens the modal dialog box which contains several operations. User selects the desired one and press OK. Now, it should apply those selected values on the selected rows in the SPGridView. Currently, It is doing the operation which is required but also disables the buttons which can only be enable after page reloads.

    If i remove the PageRefresh command then it will not refresh the page and the user can't see the changes in the SPGridView. If i reloads the page rather refresh then it will remove the SPGridView selection.

    Thanks for your prompt replies.

  51. Praveen Says:

    Nice articles,

    Closing the dialog from code:
    http://praveenbattula.blogspot.com/2011/10/close-sharepoint-2010-dialog-through.html

  52. wasi Says:

    Hi Waldek Mastykarz,

    i am having problem during the calling page in dialogue box.

    i have webpart in which i have define some hyper links and hyper links based on jsp pages. the problem is when i click on hyper link it shows error Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)
    Timestamp: Fri, 14 Oct 2011 07:33:01 UTC

    Message: Unterminated string constant
    Line: 1
    Char: 116
    Code: 0
    URI: http://sharepoint14:44469/SitePages/viewer.aspx

    and here is my code:

    function ShowDialog(url) {

    var options = SP.UI.$create_DialogOptions();
    options.url = url;
    options.height = 300;
    options.width = 600;
    SP.UI.ModalDialog.showModalDialog(options);
    }

    const string jsScriptURL = "/_catalogs/masterpage/FunctionCustom.js";

    protected override void CreateChildControls()
    {
    SPUser currentuser = SPContext.Current.Web.CurrentUser;

    HtmlGenericControl scriptInclude = new HtmlGenericControl("script");
    scriptInclude.Attributes.Add("src",
    SPContext.Current.Site.RootWeb.Url + jsScriptURL);
    Controls.Add(scriptInclude);

    //HyperLink link = new HyperLink();
    //link.Text = "View Calendar";
    //link.NavigateUrl = string.Concat("javascript: ShowDialog('",SPContext.Current.Site.RootWeb.Url,"/Lists/Calendar/calendar.aspx')");
    //this.Controls.Add(link);

    HyperLink link = new HyperLink();
    link.Text = "View Calendar";
    link.NavigateUrl = string.Concat("javascript: ShowDialog('", SPContext.Current.Site.RootWeb.Url, @"http://orapps.tapal:8080/tapal/lvapp/frameset2.jsp?U_id=" + currentuser.LoginName.Replace(@"TAPALWORLD\", "").TrimStart());
    this.Controls.Add(link);

    }

    Please help me out
    Thank you

  53. Waldek Mastykarz Says:

    @wasi: I suggest you take a look at the generated JavaScript code. Additionally using tools such as Firebug for Firefox might make it easier for you to track the bug in JavaScript.

  54. MossBuddy Says:

    Hi Waldek, hey I am trying to call an application page from the javascript and in turn that app-page will execute some serverside code and return data (keep it in session variable). Is there anyways to not show a pop-up for this app-page and simply create the session variable or return the data to the calling javascript? I am doing this for asynchronosuly populating a dropdown box in a webpart which is populated on selecting a value in another webpart. I cant use web-service here due to some constraints of claims and end user claim. So was thinking of using app page to execute server side code and get the data back to the calling webpart's javascript. any thoughts?

    thanks

  55. MossBuddy Says:

    Hi Waldek, hey I am trying to call an application page from the javascript and in turn that app-page will execute some serverside code and return data (keep it in session variable). Is there anyways to not show a pop-up for this app-page and simply create the session variable or return the data to the calling javascript? I am doing this for asynchronosuly populating a dropdown box in a webpart which is populated on selecting a value in another webpart. I cant use web-service here due to some constraints of claims and end user claim. So was thinking of using app page to execute server side code and get the data back to the calling webpart\'s javascript. any thoughts?

    thanks

  56. Waldek Mastykarz Says:

    @MossBuddy: It sounds a lot like an HTTP Handler. Have you considered that?

  57. MossBuddy Says:

    No I have not considered HTTP handler, but my confusion is when I trigger an application page from the javascript (I dnt want to show an popups) nt sure how to do it…are we saying here that lets do HTTP handler instead of application page? or is it something obvious that I am missing…the problem with nt using asmx or wcf here is that the end user identity is not making over to the wcf service in this case and wcf is showing app-pool identity and code executes under app-pool identity which is what I am trying to avoid.

  58. MossBuddy Says:

    aah..ok now I get it you meant use a ashx…(httpHandler) and eleminate the application page completely that way we can use ashx handler and get Json or HTML data from the handler…do u think this wld be a performance issue (i.e. using handler)? or it wld just be used for specific url like (getMyData.ashx) and not every http request?…thanx..

  59. Waldek Mastykarz Says:

    @MossBuddy: Pages are also HTTP Handlers but then with a lot more of functionality added. So an HTTP Handler is probably as lightweight as you can get. You can either deploy an ASHX file to Layouts or add a mapping to your web.config. Deploying ASHX is easier from the deployment point of view but at the end of the day it shouldn't really matter which one you use.

  60. MossBuddy Says:

    Thanks buddy :-)..appreciate your detailed response as always..

  61. Bharanidharan P Says:

    Thanks dude… Really nice article for beginners like me.. :)

  62. Sunil Dubey Says:

    Check this helpful link too its also having a wonderful explanation of application page in sharepoint…

    http://mindstick.com/Articles/6345ba2f-1a8b-4ccf-9c81-d656ea0b4bf2/?Custom%20Application%20Page%20in%20SharePoint

  63. RameshUSA Says:

    Hi,

    I have visual web parts with some image buttons on it. When the user clicks on it, I would like to popup a dialog box custom pages (stored in _layouts) based on what the user clicks. On Image Button click I am calling the javascript which calls for SP.Utilities.Utility.getLayoutsPageUrl(…).

    I am getting sp.Utilities.Utility is null or not an object. Where i am making a mistake? I have included client object dlls already.

    Please help.

    Thanks,

    Ramesh

  64. Waldek Mastykarz Says:

    @Ramesh: JavaScript is case-sensitive. Are you sure you have typed SP uppercase?

  65. Pawel Kaminski Says:

    Thanks Waldek. You saved a lot of my time.

  66. T Orakle Says:

    Can you explain to me how to handle Cancel button and BACK TO Previous page?

  67. Waldek Mastykarz Says:

    One thing that you could do is to read the result and if its value is Cancel call history.back() in your script.

  68. Walter Lopez Says:

    Awesome code. By far the best. Generic and re-usable.

  69. Rao Says:

    Hi Waldek
    It's Awesome code. Can you please share the code..

    Thanks in advance

  70. Waldek Mastykarz Says:

    All of the code is included in the article.

  71. Rao Says:

    i used u r code for opening popup but it is opening and suddenly closing

    plz let me know wat i am doing wrong

    here i followed following code

    var options = { url:'/_layouts/prjsetng.aspx', title:'Title, Description, and Icon', width:640, height:400 } SP.UI.ModalDialog.showModalDialog(options);

  72. Waldek Mastykarz Says:

    Have you tried using the same code snippet with another page? Could it be that the page automatically closes the dialog?

  73. Rao Says:

    yes i tried in another page also.even in that also i get same issue.I googled and i get one solution,the problem with asp.net button control.I replace asp.net button control with html button control then it's work fine.But i don't know why it is not working for asp.net button control.I placed return false in populate method in javascript but still problem is not solved..Plz suggest me to work with asp.net control

  74. Waldek Mastykarz Says:

    Could it be that it's caused by the postback which is the result of the default behavior of an ASP.NET button? Have you tried using the OnClientClick property instead OnClick?

  75. suchithra Says:

    i want to if i can open search results pages in model dialog box on click on search button(javascript:S3031AEBB_Submit())

  76. Waldek Mastykarz Says:

    You should be able to do that.

  77. Riya Says:

    Great Info! Very Very helpful!

  78. McMins Says:

    I try modal dialog and jquery. I would like to write a condition. It should be hidden the edit button in a list item from the dialog when you are on a specific page. What is missing here, or how do you do that?

    I tried this:
    if ($("td.title h1:contains('1. Ideen')").length) {
    var elem = document.getElementById("Ribbon\.ListForm\.Display\.Manage\.EditItem-Large"); elem.style.display = "none !important"; };

    or this:
    if…. {
    $("html.ms-dialog .ms-cui-tabContainer ul.ms-cui-tabBody li span span span span span:first-child a.ms-cui-ctl-large").css("display", "none !important"); };

    r dont work.. I know that can work with the right for a list, but only on the page with a list webpart should not be editable for everyone.

    What should I do now? Thanks in advance

  79. Waldek Mastykarz Says:

    Hiding Ribbon buttons using jQuery is not really the way to go. I'd suggest you use the SharePoint Ribbon API with Page Components to do this correctly rather than applying CSS directly to the Ribbon buttons.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2013 Waldek Mastykarz

Creative Commons License