Link to home
Start Free TrialLog in
Avatar of Howard Bash
Howard BashFlag for United States of America

asked on

SharePoint 2010 MasterPage Adding Codebehind

I need to add functions to my MasterPage such that any page based on this masterpage will have access to some functions I have written and tested using a standard aspx page for development.

Within the ASPX page is the following code fragment:

    //-----------------------------------------------------------------------------------------
    function CallSaveStuff(uid, src, linktext, dest, isdoc) {
        PageMethods.SaveStuff(uid, src, linktext, dest, isdoc, OnGetMessageSuccess, OnGetMessageFailure);
    }

    function OnGetMessageSuccess(result, userContext, methodName) {
        alert(result);
    }

    function OnGetMessageFailure(error, userContext, methodName) {
        alert(error.get_message());
    }

</script>


<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

and in the codebehind I have the following fragment:

[System.Web.Services.WebMethod]
        public static string SaveStuff(string UID, string SrcURL, string LinkText, string DestURL, int IsDoc)
        {
....
        }


All this works fine using jQuery to associate anchor tags with this function (CallSaveStuff) and my aspx page calls the server side function passing it the client side parameters when an anchor tag get clicked.

I need to move this aspx code for server side execution to my v4 master page to allow this function to be called when any anchor tag on a page derived from v4 is clicked on.

It looks like I need to add codebehind to the v4.master page however the technique to use is not obvious.
SOLUTION
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Howard Bash

ASKER

The link for some reason sends me to Connell's site,  but the code on the page must be embedded in image files as clicking goes to Flickr and they don't open???  Also this referrs to attaching to an aspx page not a master page (perhaps the same technique - which I cannot see)?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have read that putting the code in the master page as opposed to in a codebehind is considered a "Best Practice" and would prefer not to do so.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried embedding the code (for the "experiment") and the page launches and tells me that this page does not allow code.
I'm not really clear on the building and placement of the codebehind file and/or DLLs from project link referenced above.  

A complete example: "Create VS2010 project",  "Save it to folder X",  "Copy file(s) to folder Y" etc.  would clear this up.