views:

176

answers:

2

Hello everyone,

I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I have the following code which works correctly in ASP.Net (aspx) and I want to implement the same function in a WebPart and deploy into a page of SharePoint publishing portal site.

Any ideas how to implement? My major confusion is how to deal with the code in the head part of the following code? Any reference code or document?

Here is the aspx code I am using,

<!doctype html>
<html lang="en">
<head>
    <title>Test</title>
    <link type="text/css" href="tabcontrol/themes/base/ui.all.css" rel="stylesheet" />
    <script type="text/javascript" src="tabcontrol/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#tabs").tabs();
        });
    </script>
</head>
<body>

<div class="demo">

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">tab1</a></li>
        <li><a href="#tabs-2">tab2</a></li>
    </ul>
    <div id="tabs-1">
        <p>tab1 info</p>
    </div>
    <div id="tabs-2">
        <p>tab2 info</p>
    </div>
</div>

</div>

</body>
</html>

thanks in advance, George

+2  A: 

Check this links...

http://dotnet.org.za/zlatan/archive/2007/10/12/developing-ajax-web-parts-in-sharepoint-2007.aspx

http://www.bewise.fr/article/ptc/57/WSS-V3-Use-ASP-NET-AJAX-Framework-with-WSS-30.aspx

If you need help tell me that I can provide you a WebPart sample.


To include css or js files you can do something like this...

 protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);



            ClientScriptManager cs = Page.ClientScript;

            string includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
            string includeLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "App_Themes.MyButtons.css");
            LiteralControl include = new LiteralControl(String.Format(includeTemplate, includeLocation));
            Page.Header.Controls.Add(include);

            includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
            includeLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "App_Themes.MyMainModalDialog.css");
            include = new LiteralControl(String.Format(includeTemplate, includeLocation));
            Page.Header.Controls.Add(include);


        }

In this sample I include MyMainModalDialog.css and MyButtons.css dynamically

Guilherme Ferreira
My confusion is how to use register script API in my specific case to register the js and css files? Any ideas?
George2
A: 

For the CSS, you can use CssLink and CssRegistration:

// Custom CSS (fix the URL as necessary)
Microsoft.SharePoint.WebControls.CssLink cssLink =
    new Microsoft.SharePoint.WebControls.CssLink(); 
cssLink.DefaultUrl = "/tabcontrol/themes/base/ui.all.css";
this.Page.Header.Controls.Add(cssLink);

I forget if there are other ways to handle custom javascript besides ClientScriptManager or Page.Header.Controls.Add(). There is a CustomJSUrl class but it doesn't seem to operate in the same way that the CssLink works.

Also, I believe your formatting script $(function() { $("#tabs").tabs() }) should be hooked to the page.load event rather than in the <head> block.

Ryan