SharePoint(WSS)學習(3) 整合ASP.NET AJAX

來源:互聯網
上載者:User
SharePoint整合ASP.NET AJAX能大大改善使用者體驗,實現起來也不麻煩。本篇用上篇的WebPart樣本整合ASP.NET AJAX。
SharePoint整合ASP.NET AJAX的關鍵是設定檔。(註:這裡用的ASP.NET AJAX 3.5,如果用1.0應該也可以,沒有測試。)

添加System.Web.Extensions的引用。
程式碼:TextBox txt1 = new TextBox();
DropDownList ddl1 = new DropDownList();
TextBox txt2 = new TextBox();
HtmlGenericControl lbl1 = new HtmlGenericControl("span");
TextBox txt3 = new TextBox();
Button btn1 = new Button();
HtmlGenericControl lbl2 = new HtmlGenericControl("span");

protected override void CreateChildControls()
{
    txt2.Width = ddl1.Width = txt1.Width = 40;

    ddl1.Items.Add("+");
    ddl1.Items.Add("-");
    ddl1.Items.Add("*");
    ddl1.Items.Add("/");

    lbl1.InnerHtml = "=";

    btn1.Text = "Calculate";
    btn1.Click += new EventHandler(btn1_Click);

    lbl2.Style.Add("color", "red");

    //添加ScriptManager和UpdatePanel,把控制項放到UpdatePanel內。
    ScriptManager sm = new ScriptManager();
    this.Controls.Add(sm);

    UpdatePanel up = new UpdatePanel();
    up.ContentTemplateContainer.Controls.Add(txt1);
    up.ContentTemplateContainer.Controls.Add(ddl1);
    up.ContentTemplateContainer.Controls.Add(txt2);
    up.ContentTemplateContainer.Controls.Add(lbl1);
    up.ContentTemplateContainer.Controls.Add(lbl2);
    up.ContentTemplateContainer.Controls.Add(btn1);

    this.Controls.Add(up);
}

設定檔比較複雜,比較簡單的方法是建立一個.NET 3.5的Web Application,這個Web Application本身支援ASP.NET AJAX 3.5,只需把這個Web Application的web.config與SharePoint網站的web.config合并即可。
編譯部署後可以看到能夠無重新整理的執行操作。

樣本下載:點擊下載

飄遙的BLOG:http://www.cnblogs.com/zxjay/
作者:飄遙(周振興)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.