Request from server

According to the above codes, we have an HTML page in which there is a JavaScript method to receive the response of a page in AJAX form.

Executing the JavaScript method causes three things to happen:
1- Finding the content of a page from the server and adding it to a part of the HTML page
2- Changing the background color
3- Set right to left for one of the tags

Note: options 2 and 3 are done on the client side, and if we want to change them from the server, we need to request the server twice more or we have to retrieve all three options with one request in a complicated process.

In order to support WebFormsJS, we rewrote the above HTML page as below.

Using WebFormsJS

    

Request from server

We copied the web-forms.js file from the link below and saved it in the script/web-forms.js path.

https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js

When we request the page from the server, the server sends the following response.

Server response

[web-forms]stMyTag=Server response textbc=#409354ta

=right

We at Elanat team call this structure Action Controls. Action Controls are WebFormsJS received codes that are received in INI format. WebFormsJS automatically detects whether the server response has Action Controls or not. If the server\\'s response is based on the structure of an INI file that starts with [web-forms], it will process the Action Controls, otherwise it will replace the server\\'s response in the form of AJAX on the page.

WebFormsJS on the server-side

If you use a flexible back-end framework, you can easily create a process for generating Action Controls; otherwise, you can ask the owners or developers to rewrite the core of the back-end framework or create a new module to support WebFormsJS.

An example of using WebFormsJS in the CodeBehind framework

We create a new View in which there is an input of select type; we want to add new option values ​​in select, so we put two textbox input for the name and value of the new option in the View, and we also create a checkbox input for whether the new option is selected or not in this View.

View (Form.aspx)

@page@controller FormController        Send Form Data        




We first activate the IgnoreViewAndModel attribute; by doing this, we prevent the View page from returning. Then we create an instance of the WebForms class and add a new value in the drop-down list according to the values ​​sent through the Form method. Finally, we must place the created instance of the WebForms class inside the Control method.

Controller (FormController)

public partial class FormController : CodeBehindController{    public void PageLoad(HttpContext context)    {        if (!string.IsNullOrEmpty(context.Request.Form[\\\"btn_Button\\\"]))            btn_Button_Click(context);    }    private void btn_Button_Click(HttpContext context)    {        IgnoreViewAndModel = true;        Random rand = new Random();        string RandomColor = \\\"#\\\"   rand.Next(16).ToString(\\\"X\\\")   rand.Next(16).ToString(\\\"X\\\")   rand.Next(16).ToString(\\\"X\\\")   rand.Next(16).ToString(\\\"X\\\")   rand.Next(16).ToString(\\\"X\\\")   rand.Next(16).ToString(\\\"X\\\");        WebForms Form = new WebForms();        string SelectValue = context.Request.Form[\\\"txt_SelectValue\\\"];        string SelectName = context.Request.Form[\\\"txt_SelectName\\\"];        bool SelectIsChecked = context.Request.Form[\\\"cbx_SelectIsSelected\\\"] == \\\"on\\\";        Form.AddOptionTag(InputPlace.Id(\\\"ddlst_Select\\\"), SelectName, SelectValue, SelectIsChecked);        Form.SetBackgroundColor(InputPlace.Tag(\\\"body\\\"), RandomColor);        Control(Form);    }}

Each time the button is clicked, new values ​​are added to the drop-down list and the background changes to a random color.

This is a simple example of CodeBehind framework interaction with WebFormsJS.

These features will be available in version 2.9 of the CodeBehind framework. In the coming days, version 2.9 of the CodeBehind framework will be released.

Advantages of WebFormsJS over using JavaScript and AJAX:

In contrast, using JavaScript and AJAX:

Comparison with Frontend Frameworks

Frontend frameworks like React, Angular, and Vue have gained popularity in recent years for their ability to create dynamic and interactive user interfaces. However, compared to WebFormsJS, they have some key differences:

Complexity: Frontend frameworks can be complex to set up and require a deep understanding of JavaScript and the framework itself. In contrast, WebFormsJS simplifies web development by allowing developers to focus on server-side interactions and control the HTML elements.

Performance: While frontend frameworks offer high performance and efficiency, WebFormsJS also boasts high performance and low bandwidth consumption. It efficiently manages server responses and controls HTML tags, reducing the complexity of web development.

Customization: Frontend frameworks offer extensive customization options and flexibility to create unique user interfaces. WebFormsJS also provides customization options, such as postback, progress bar, and script extraction, but focuses more on server-side interaction.

Action Controls: WebFormsJS introduces the concept of Action Controls, which are received in INI format to define specific actions for HTML tags. This provides a clear and structured way to handle server responses and modify controls on the page.

Conclusion

WebFormsJS is a powerful JavaScript library that simplifies web development by providing a robust infrastructure for interacting with web controls on the server-side. Its advanced system, low bandwidth consumption, and customization options make it an attractive choice for developers looking to build efficient and scalable web applications.

Related links

WebFormsJS on GitHub:
https://github.com/elanatframework/Web_forms

CodeBehind on GitHub:
https://github.com/elanatframework/Code_behind

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind/

CodeBehind page:
https://elanat.net/page_content/code_behind

","image":"http://www.luping.net/uploads/20240730/172231704666a878f68875b.jpg","datePublished":"2024-07-30T13:24:06+08:00","dateModified":"2024-07-30T13:24:06+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}
」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > GitHub 上的新儲存庫 WebFormsJS 就在這裡!

GitHub 上的新儲存庫 WebFormsJS 就在這裡!

發佈於2024-07-30
瀏覽:968

New Repository on GitHub, WebFormsJS is Here!

WebFormsJS is a JavaScript library that provides the infrastructure for interacting with web controls in the CodeBehind framework; this allows developers to easily manage HTML tags on the server-side.

A New Architecture for Efficient Web Development

Web development has always been a complex and time-consuming process, with multiple layers of complexity and numerous technologies to manage. WebFormsJS is a new JavaScript library that simplifies this process by providing a robust infrastructure for interacting with web controls (HTML tags) on the server-side, allowing developers to focus on server responses without worrying about the front-end.

Using WebFormsJS eliminates the need for front-end development to a large extent. You will no longer need to use front-end frameworks such as React, Angular and Vue, and you will not even need to work with JavaScript on the front-end. Please note that the simultaneous use of WebFormsJS with front-end frameworks or JavaScript also gives many advantages to your project.

Please see the following example:

This is an HTML page that requests a page from the server to add its contents inside a div tag with the id MyTag.

Simple AJAX whih JavaScript



    


Request from server

According to the above codes, we have an HTML page in which there is a JavaScript method to receive the response of a page in AJAX form.

Executing the JavaScript method causes three things to happen:
1- Finding the content of a page from the server and adding it to a part of the HTML page
2- Changing the background color
3- Set right to left for one of the tags

Note: options 2 and 3 are done on the client side, and if we want to change them from the server, we need to request the server twice more or we have to retrieve all three options with one request in a complicated process.

In order to support WebFormsJS, we rewrote the above HTML page as below.

Using WebFormsJS



    



Request from server

We copied the web-forms.js file from the link below and saved it in the script/web-forms.js path.

https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js

When we request the page from the server, the server sends the following response.

Server response

[web-forms]
stMyTag=Server response text
bc=#409354
ta

=right

We at Elanat team call this structure Action Controls. Action Controls are WebFormsJS received codes that are received in INI format. WebFormsJS automatically detects whether the server response has Action Controls or not. If the server's response is based on the structure of an INI file that starts with [web-forms], it will process the Action Controls, otherwise it will replace the server's response in the form of AJAX on the page.

  • Line 1: stMyTag=Server response text Here, the first two characters are st, which means to set the text, and then it is specified that it should be applied to a tag with the id MyTag, and after the equal character (=) there is the received text.
  • Line 2: bc=#409354 Here, the first two characters are bc, which means the background color, and then it is specified that it should be applied to the body tag, and after the equal character (=) there is the color value.
  • Line 3: ta

    =right Here, the first two characters are ta, which means text align, and then it is determined that it will be applied to a tag named li, and after the equal character (=) there is a value of right which means right to left.

WebFormsJS on the server-side

If you use a flexible back-end framework, you can easily create a process for generating Action Controls; otherwise, you can ask the owners or developers to rewrite the core of the back-end framework or create a new module to support WebFormsJS.

An example of using WebFormsJS in the CodeBehind framework

We create a new View in which there is an input of select type; we want to add new option values ​​in select, so we put two textbox input for the name and value of the new option in the View, and we also create a checkbox input for whether the new option is selected or not in this View.

View (Form.aspx)

@page
@controller FormController



    
    Send Form Data
    


    




We first activate the IgnoreViewAndModel attribute; by doing this, we prevent the View page from returning. Then we create an instance of the WebForms class and add a new value in the drop-down list according to the values ​​sent through the Form method. Finally, we must place the created instance of the WebForms class inside the Control method.

Controller (FormController)

public partial class FormController : CodeBehindController
{
    public void PageLoad(HttpContext context)
    {
        if (!string.IsNullOrEmpty(context.Request.Form["btn_Button"]))
            btn_Button_Click(context);
    }

    private void btn_Button_Click(HttpContext context)
    {
        IgnoreViewAndModel = true;

        Random rand = new Random();
        string RandomColor = "#"   rand.Next(16).ToString("X")   rand.Next(16).ToString("X")   rand.Next(16).ToString("X")   rand.Next(16).ToString("X")   rand.Next(16).ToString("X")   rand.Next(16).ToString("X");

        WebForms Form = new WebForms();

        string SelectValue = context.Request.Form["txt_SelectValue"];
        string SelectName = context.Request.Form["txt_SelectName"];
        bool SelectIsChecked = context.Request.Form["cbx_SelectIsSelected"] == "on";

        Form.AddOptionTag(InputPlace.Id("ddlst_Select"), SelectName, SelectValue, SelectIsChecked);
        Form.SetBackgroundColor(InputPlace.Tag("body"), RandomColor);

        Control(Form);
    }
}

Each time the button is clicked, new values ​​are added to the drop-down list and the background changes to a random color.

This is a simple example of CodeBehind framework interaction with WebFormsJS.

These features will be available in version 2.9 of the CodeBehind framework. In the coming days, version 2.9 of the CodeBehind framework will be released.

Advantages of WebFormsJS over using JavaScript and AJAX:

  • Simplified code: WebFormsJS provides a simpler and more concise way of interacting with web controls on the server-side, reducing the complexity of code and making it easier to maintain.
  • Automatic form serialization: WebFormsJS automatically serializes form data, eliminating the need to manually serialize and deserialize data using techniques like JSON or XML.
  • Progress bar: WebFormsJS includes a progress bar that displays the amount of data sent on the screen, providing a more engaging user experience.
  • Server-Side processing: WebFormsJS allows for server-side processing of form data, enabling more complex logic and validation to be performed on the server-side.
  • Support for multiple controls: WebFormsJS supports multiple controls, including checkboxes, radio buttons, select boxes, and text inputs, making it easy to interact with multiple controls on the server-side.
  • Customizable: WebFormsJS provides customizable options, such as the ability to set the progress bar display, error messages, and other settings.
  • Robust infrastructure: WebFormsJS provides a robust infrastructure for interacting with web controls on the server-side, making it suitable for large-scale applications.

In contrast, using JavaScript and AJAX:

  • Requires manual serialization and deserialization of form data
  • Does not provide a progress bar or error handling
  • Does not support multiple controls or server-side processing
  • Is more verbose and complex to use

Comparison with Frontend Frameworks

Frontend frameworks like React, Angular, and Vue have gained popularity in recent years for their ability to create dynamic and interactive user interfaces. However, compared to WebFormsJS, they have some key differences:

Complexity: Frontend frameworks can be complex to set up and require a deep understanding of JavaScript and the framework itself. In contrast, WebFormsJS simplifies web development by allowing developers to focus on server-side interactions and control the HTML elements.

Performance: While frontend frameworks offer high performance and efficiency, WebFormsJS also boasts high performance and low bandwidth consumption. It efficiently manages server responses and controls HTML tags, reducing the complexity of web development.

Customization: Frontend frameworks offer extensive customization options and flexibility to create unique user interfaces. WebFormsJS also provides customization options, such as postback, progress bar, and script extraction, but focuses more on server-side interaction.

Action Controls: WebFormsJS introduces the concept of Action Controls, which are received in INI format to define specific actions for HTML tags. This provides a clear and structured way to handle server responses and modify controls on the page.

Conclusion

WebFormsJS is a powerful JavaScript library that simplifies web development by providing a robust infrastructure for interacting with web controls on the server-side. Its advanced system, low bandwidth consumption, and customization options make it an attractive choice for developers looking to build efficient and scalable web applications.

Related links

WebFormsJS on GitHub:
https://github.com/elanatframework/Web_forms

CodeBehind on GitHub:
https://github.com/elanatframework/Code_behind

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind/

CodeBehind page:
https://elanat.net/page_content/code_behind

版本聲明 本文轉載於:https://dev.to/elanatframework/new-repository-on-github-webformsjs-is-here-2045?1如有侵犯,請洽[email protected]刪除
最新教學 更多>
  • 儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    解決PHP 中的POST 請求故障在提供的程式碼片段:action=''而非:action="<?php echo $_SERVER['PHP_SELF'];?>";?>"檢查$_POST陣列:表單提交後使用 var_dump 檢查 $_POST 陣列的內容...
    程式設計 發佈於2024-12-19
  • 插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入記錄時如何解決「一般錯誤:2006 MySQL 伺服器已消失」介紹:將資料插入MySQL 資料庫有時會導致錯誤「一般錯誤:2006 MySQL 伺服器已消失」。當與伺服器的連線遺失時會出現此錯誤,通常是由於 MySQL 配置中的兩個變數之一所致。 解決方案:解決此錯誤的關鍵是調整wait_tim...
    程式設計 發佈於2024-12-19
  • 使用 html css 和 javascript 幻覺的 Tic-Tac-Toe 遊戲 https://www.instagram.com/webstreet_code/
    使用 html css 和 javascript 幻覺的 Tic-Tac-Toe 遊戲 https://www.instagram.com/webstreet_code/
    在 Instagram 上關注我們:https://www.instagram.com/webstreet_code/ ? ✨ 有玻璃效果的井字遊戲! ✨? 我剛剛使用 HTML、CSS 和 JavaScript 構建了一款經典的 Tic-Tac-Toe 遊戲,具有時尚的玻璃態設計。觀看視頻,看看...
    程式設計 發佈於2024-12-19
  • 如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    在 PHP 中組合關聯數組在 PHP 中,將兩個關聯數組組合成一個數組是常見任務。考慮以下請求:問題描述:提供的代碼定義了兩個關聯數組,$array1和$array2。目標是建立一個新陣列 $array3,它合併兩個陣列中的所有鍵值對。 此外,提供的陣列具有唯一的 ID,而名稱可能重疊。要求是建構一...
    程式設計 發佈於2024-12-19
  • 在 Go 中使用 WebSocket 進行即時通信
    在 Go 中使用 WebSocket 進行即時通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    程式設計 發佈於2024-12-19
  • Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta:列偏移的刪除和恢復Bootstrap 4 在其Beta 1 版本中引入了重大更改柱子偏移了。然而,隨著 Beta 2 的後續發布,這些變化已經逆轉。 從 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    程式設計 發佈於2024-12-19
  • 大批
    大批
    方法是可以在物件上呼叫的 fns 數組是對象,因此它們在 JS 中也有方法。 slice(begin):將陣列的一部分提取到新數組中,而不改變原始數組。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index ...
    程式設計 發佈於2024-12-19
  • TB 級資料庫的 MySQL 與 NoSQL:聚集索引何時是正確的解決方案?
    TB 級資料庫的 MySQL 與 NoSQL:聚集索引何時是正確的解決方案?
    MySQL:探索資料庫設計迷宮優化大型資料庫時,必須考慮資料庫設計策略以提高效能。在給定的場景中,包含執行緒的 TB 級資料庫由於其龐大的規模而面臨效能挑戰。本文探討了 MySQL 和 NoSQL 之間的選擇,重點介紹了 MySQL 的 innodb 引擎及其聚集索引的優點。 了解 MySQL 的 ...
    程式設計 發佈於2024-12-19
  • 為什麼我的 Spring Boot 應用程式不自動建立資料庫架構?
    為什麼我的 Spring Boot 應用程式不自動建立資料庫架構?
    在 Spring Boot 中自動建立資料庫架構啟動 Spring Boot 應用程式時,可能會遇到自動建立資料庫架構的問題。以下故障排除步驟旨在解決此問題:1.實體類別包:確保實體類別位於使用@EnableAutoConfiguration註解的類別的同一個套件或子包中。否則,Spring 將不會...
    程式設計 發佈於2024-12-18
  • CSS3 轉場是否提供事件來偵測起點和終點?
    CSS3 轉場是否提供事件來偵測起點和終點?
    了解 CSS3 過渡事件CSS3 過渡允許在 Web 元素上實現流暢的動畫和視覺效果。為了增強使用者體驗並使操作與這些轉換同步,監控其進度非常重要。本文解決了 CSS3 是否提供事件來檢查過渡何時開始或結束的問題。 W3C CSS 過渡草案W3C CSS 過渡草案規定CSS 轉換會觸發對應的 DOM...
    程式設計 發佈於2024-12-18
  • Java 中可以手動釋放記憶體嗎?
    Java 中可以手動釋放記憶體嗎?
    Java 中的手動內存釋放與垃圾回收與C 不同,Java 採用託管內存框架來處理內存分配和釋放由垃圾收集器(GC) 自動執行。這種自動化方法可以提高記憶體利用率並防止困擾 C 程式的記憶體洩漏。 Java 中可以手動釋放記憶體嗎? 由於 Java 的記憶體管理是由GC,它沒有提供像 C 中的 fre...
    程式設計 發佈於2024-12-18
  • Java 1.6 中如何可靠地確定檔案是否為符號連結?
    Java 1.6 中如何可靠地確定檔案是否為符號連結?
    在 Java 1.6 中驗證符號連結確定符號連結的存在對於各種文件處理操作至關重要。在 Java 中,識別符號連結時需要考慮一些潛在問題,特別是在目錄遍歷的上下文中。 檢查符號連結的常見方法是比較文件的絕對路徑和規範路徑。規範路徑表示檔案的標準化路徑,而絕對路徑可能包括符號連結。傳統上,概念是如果這...
    程式設計 發佈於2024-12-17
  • 如何使背景顏色透明,同時保持文字不透明?
    如何使背景顏色透明,同時保持文字不透明?
    背景顏色的不透明度而不影響文本在Web 開發領域,實現透明度通常對於增強視覺吸引力和網站元素的功能。常見的要求是對 div 背景套用透明度,同時保留所包含文字的不透明度。這可能會帶來挑戰,特別是在確保跨瀏覽器相容性方面。 rgba 解決方案最有效且廣泛支持的解決方案是利用「RGBA」(紅、綠、藍、A...
    程式設計 發佈於2024-12-17
  • PHP 字串比較:`==`、`===` 或 `strcmp()` – 您應該使用哪個運算子?
    PHP 字串比較:`==`、`===` 或 `strcmp()` – 您應該使用哪個運算子?
    PHP 中的字串比較:'=='、'===' 或 'strcmp()'? PHP 中的字串比較PHP 可以使用不同的運算子來完成,例如「==」、「===」或「strcmp()」函數。此比較涉及檢查兩個字串是否相等。 '==' 與'...
    程式設計 發佈於2024-12-17
  • 如何自訂操作列的按鈕和外觀?
    如何自訂操作列的按鈕和外觀?
    自訂操作欄的按鈕和外觀要實現所需的自訂操作欄外觀,請考慮以下步驟: 1.建立自訂操作按鈕若要將圖片包含為按鈕,請透過擴充Button類別來定義自訂視圖。然後可以將此自訂視圖顯示在 ActionBar 上,如下所示:<Button android:id="@ id/my_cus...
    程式設計 發佈於2024-12-17

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3