通過HTML調用C# [架構]

來源:互聯網
上載者:User

先看一下HTML代碼:

<html>
  <head>
    <title>Demo for how to call C# business from html page</title>
    <script src="http://www.zivosft.com/core/lib.js"></script>
  </head>
  <body>
    <form id="default" action="Zivsoft.Business.DemoShow.AddSample">
        <input id="a" type="text">+
        <input id="b" type="text">+
        <input id="c" type="text">=
        <input id="txt" type='text'>
        <input type="button" id="add" value="submit" onclick="CallBusiness();">
    </form>
  </body>
</html>

再看一下HTML介面:

以上是一個非常簡單的Demo,來示範通過HTML介面構造三個輸入框,並調用後代C#邏輯Zivsoft.Business.DemoShow.AddSample實現三個數相加求和的功能。

 

下面看一下後台C#商務邏輯:

namespace Zivsoft.Business.DemoShow
{
       public class AddSample:BaseControl       {
              private void Add_Click(IComponent com)
              {
                  this.txt.Value =  System.Convert.ToInt32(this.tba.Value)                                + System.Convert.ToInt32(this.tbb.Value)                                + System.Convert.ToInt32(this.tbc.Value);              }       }
}

最後看看一段JavaScript代碼:

        var url = http://www.zivsoft.com/cloudserver/default.aspx;
        req.open("POST", url, async);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        while (reqData.indexOf('/') != -1)         {            reqData = reqData.replace('/', '%2F');        }
        reqData = reqData.replace(/\</g, "%3D");
        reqData = reqData.replace(/\>/g, "%3E");
        //發送請求資料給雲端ASPX程式
        req.send(reqData);
        if (!async)         {
            if (req.status == 200)             {
                return req.responseText;
            }             else             {
                alert('cloud server error');
            }
        }

 

不多寫了,童鞋們知道怎麼回事了吧?

現在技術日新月異,終端程式層次不齊,有XAML,HTML5等等,UI雖然越來越絢麗美觀了,應用終端也越來越多了,如Android, WP7等,但不變的是後端的服務。精通C#或Java的童鞋趕緊加入雲端運算的後台來吧!!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.