将asp.net代码转换为WebPart代码问题

发布于 2024-08-17 05:49:48 字数 1199 浏览 3 评论 0原文

我将 SharePoint Server 2007 Enterprise 与 Windows Server 2008 Enterprise 结合使用。我正在使用 VSTS 2008 + C# + .Net 3.5 + ASP.Net 进行开发。我有以下代码,可以在 ASP.Net (aspx) 中正常工作,并且我想在 WebPart 中实现相同的功能并部署到 SharePoint 发布门户网站的页面中。

有什么想法如何实施吗?我主要的困惑是如何处理以下代码的头部部分的代码?有参考代码或文档吗?

这是我正在使用的aspx代码,

<!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>

提前致谢, 乔治

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染墨丶若流云 2024-08-24 05:49:48

检查此链接...

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

如果您需要帮助,请告诉我,我可以为您提供 WebPart 示例。


要包含 css 或 js 文件,您可以执行以下操作...

 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);


        }

在此示例中,我动态包含 MyMainModalDialog.css 和 MyButtons.css

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

青朷 2024-08-24 05:49:48

对于 CSS,您可以使用 CssLinkCssRegistration

// 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);

我忘记是否有除了 ClientScriptManager 或 Page.Header.Controls.Add() 之外,还有其他处理自定义 javascript 的方法。有一个 CustomJSUrl 类,但它没有似乎与 CssLink 的工作方式不同。

另外,我相信您的格式化脚本 $(function() { $("#tabs").tabs() }) 应该挂钩到 page.load 事件而不是 < ;head> 块。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文