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
浏览:147

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]删除
最新教程 更多>
  • 在 Go 中使用 WebSocket 进行实时通信
    在 Go 中使用 WebSocket 进行实时通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    编程 发布于2024-12-19
  • TB 级数据库的 MySQL 与 NoSQL:聚集索引何时是正确的解决方案?
    TB 级数据库的 MySQL 与 NoSQL:聚集索引何时是正确的解决方案?
    MySQL:探索数据库设计迷宫优化大型数据库时,必须考虑数据库设计策略以提高性能。在给定的场景中,包含线程的 TB 级数据库由于其庞大的规模而面临性能挑战。本文探讨了 MySQL 和 NoSQL 之间的选择,重点介绍了 MySQL 的 innodb 引擎及其聚集索引的优势。了解 MySQL 的 In...
    编程 发布于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
  • 除了“if”语句之外:还有什么地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    除了“if”语句之外:还有什么地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    无需强制转换即可上下文转换为 bool您的类定义了对 bool 的显式转换,使您能够在条件语句中直接使用其实例“t”。然而,这种显式转换提出了一个问题:“t”在哪里可以在不进行强制转换的情况下用作 bool?上下文转换场景C 标准指定了四种值可以根据上下文转换为的主要场景bool:语句:if、whi...
    编程 发布于2024-12-19
  • 尽管代码有效,为什么 POST 请求无法捕获 PHP 中的输入?
    尽管代码有效,为什么 POST 请求无法捕获 PHP 中的输入?
    解决 PHP 中的 POST 请求故障在提供的代码片段中:action=''而不是:action="<?php echo $_SERVER['PHP_SELF'];?>";?>"检查 $_POST数组:表单提交后使用 var_dump 检查 $_POST 数...
    编程 发布于2024-12-19
  • 大批
    大批
    方法是可以在对象上调用的 fns 数组是对象,因此它们在 JS 中也有方法。 slice(begin):将数组的一部分提取到新数组中,而不改变原始数组。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index p...
    编程 发布于2024-12-19
  • 插入数据时如何修复“常规错误:2006 MySQL 服务器已消失”?
    插入数据时如何修复“常规错误:2006 MySQL 服务器已消失”?
    插入记录时如何解决“一般错误:2006 MySQL 服务器已消失”介绍:将数据插入 MySQL 数据库有时会导致错误“一般错误:2006 MySQL 服务器已消失”。当与服务器的连接丢失时会出现此错误,通常是由于 MySQL 配置中的两个变量之一所致。解决方案:解决此错误的关键是调整wait_tim...
    编程 发布于2024-12-19
  • 如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    在 PHP 中组合关联数组在 PHP 中,将两个关联数组组合成一个数组是一项常见任务。考虑以下请求:问题描述:提供的代码定义了两个关联数组,$array1 和 $array2。目标是创建一个新数组 $array3,它合并两个数组中的所有键值对。 此外,提供的数组具有唯一的 ID,而名称可能重合。要求...
    编程 发布于2024-12-19
  • 如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 识别今天生日的用户使用 MySQL 确定今天是否是用户的生日涉及查找生日匹配的所有行今天的日期。这可以通过一个简单的 MySQL 查询来实现,该查询将存储为 UNIX 时间戳的生日与今天的日期进行比较。以下 SQL 查询将获取今天有生日的所有用户: FROM USERS ...
    编程 发布于2024-12-19
  • 如何修复 macOS 上 Django 中的“配置不正确:加载 MySQLdb 模块时出错”?
    如何修复 macOS 上 Django 中的“配置不正确:加载 MySQLdb 模块时出错”?
    MySQL配置不正确:相对路径的问题在Django中运行python manage.py runserver时,可能会遇到以下错误:ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-...
    编程 发布于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 中的 free() ...
    编程 发布于2024-12-18
  • Java 1.6 中如何可靠地确定文件是否为符号链接?
    Java 1.6 中如何可靠地确定文件是否为符号链接?
    在 Java 1.6 中验证符号链接确定符号链接的存在对于各种文件处理操作至关重要。在 Java 中,识别符号链接时需要考虑一些潜在问题,特别是在目录遍历的上下文中。检查符号链接的一种常见方法是比较文件的绝对路径和规范路径。规范路径表示文件的标准化路径,而绝对路径可能包括符号链接。传统上,概念是如果...
    编程 发布于2024-12-17
  • 如何使背景颜色透明,同时保持文本不透明?
    如何使背景颜色透明,同时保持文本不透明?
    背景颜色的不透明度而不影响文本在 Web 开发领域,实现透明度通常对于增强视觉吸引力和网站元素的功能。一项常见的要求是对 div 背景应用透明度,同时保留所包含文本的不透明度。这可能会带来挑战,特别是在确保跨浏览器兼容性方面。rgba 解决方案最有效且得到广泛支持的解决方案是利用“RGBA”(红、绿...
    编程 发布于2024-12-17

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3