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

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]删除
最新教程 更多>
  • 如何使用PHP将斑点(图像)正确插入MySQL?
    如何使用PHP将斑点(图像)正确插入MySQL?
    在尝试将image存储在mysql数据库中时,您可能会遇到一个可能会遇到问题。本指南将提供成功存储您的图像数据的解决方案。 easudy values('$ this-> image_id','file_get_contents($ tmp_image)...
    编程 发布于2025-02-06
  • 为什么我的GO数据库/SQL查询要比直接Postgres PSQL查询要慢?
    为什么我的GO数据库/SQL查询要比直接Postgres PSQL查询要慢?
    使用数据库/sql的查询比直接查询数据库 QUERYing明显慢,尽管使用了相同的查询,但在执行A执行一个明显的性能差异使用Postgres的PSQL实用程序直接查询,并使用GO应用程序中的数据库/SQL软件包进行查询。这种差异在PSQL中毫无疑问的查询占GO中的数十毫秒。数据库/SQL初始化了一...
    编程 发布于2025-02-06
  • 版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    在默认值中使用current_timestamp或mysql版本中的current_timestamp或在5.6.5 这种限制源于遗产实现的关注,这些限制需要为Current_timestamp功能提供特定的实现。消息和相关问题 `Productid` int(10)unsigned not ...
    编程 发布于2025-02-06
  • 如何在JavaScript对象中动态设置键?
    如何在JavaScript对象中动态设置键?
    如何为JavaScript对象变量创建动态键,尝试为JavaScript对象创建动态键,使用此Syntax jsObj['key' i] = 'example' 1;将不起作用。正确的方法采用方括号:他们维持一个长度属性,该属性反映了数字属性(索引)和一个数字属性的数量。标准对象没有模仿这...
    编程 发布于2025-02-06
  • 我可以将加密从McRypt迁移到OpenSSL,并使用OpenSSL迁移MCRYPT加密数据?
    我可以将加密从McRypt迁移到OpenSSL,并使用OpenSSL迁移MCRYPT加密数据?
    将我的加密库从mcrypt升级到openssl 问题:是否可以将我的加密库从McRypt升级到OpenSSL?如果是这样?使用openssl?答案:可以使用mcrypt数据加密数据,可以使用openssl。关于如何使用openssl对McRypt进行加密的数据: openssl_decrypt...
    编程 发布于2025-02-06
  • 如何通过JavaScript中的键找到嵌套对象?
    如何通过JavaScript中的键找到嵌套对象?
    通过键 recursive solutive ); 如果(结果){ 休息; } } } 别的 { 对于(theObject中的var Prop){ con...
    编程 发布于2025-02-06
  • 我如何使用Laravel \'s“ Orderby”关系订购相关的模型记录?
    我如何使用Laravel \'s“ Orderby”关系订购相关的模型记录?
    在Laravel中与Laravel的订单关系一起检索相关的模型记录,从相关模型访问数据时,可以对使用订单方法的结果。例如,以下代码检索作者的所有注释,并将它们显示在列表中:但是,该列表不可用所需的序列排序。要根据帖子ID订购结果,您可以扩展与查询函数的关系:'列'参数指定要进行排序...
    编程 发布于2025-02-06
  • 如何使用不同数量列的联合数据库表?
    如何使用不同数量列的联合数据库表?
    合并列数不同的表 当尝试合并列数不同的数据库表时,可能会遇到挑战。一种直接的方法是在列数较少的表中,为缺失的列追加空值。 例如,考虑两个表,表 A 和表 B,其中表 A 的列数多于表 B。为了合并这些表,同时处理表 B 中缺失的列,请按照以下步骤操作: 确定表 B 中缺失的列,并将它们添加到表的末...
    编程 发布于2025-02-06
  • PHP启动错误:为什么可以加载动态库?
    PHP启动错误:为什么可以加载动态库?
    [2遇到错误消息,表明未能加载动态库。这些错误可能会显着影响PHP功能,这对于迅速解决和解决这些错误至关重要。此问题的一个常见原因是试图加载未安装的PHP扩展程序。要确定相关扩展名,请搜索PHP配置文件中包含扩展名=的行。利用GREP命令在PHP配置目录中递归搜索:修改适当的配置文件,然后重新启动a...
    编程 发布于2025-02-06
  • 潜入系统编程:C的初学者指南
    潜入系统编程:C的初学者指南
    探索系统编程:C 语言初学者指南系统编程涉及与计算机底层硬件和软件交互。C 语言是系统编程的首选语言之一,因为它能够直接访问硬件资源。这篇指南将带你踏上系统编程之旅,从 C 语言基础到实际应用案例。C 语言基础变量和数据类型:变量用于存储数据。在 C 中,变量必须声明其数据类型,例如:int age...
    编程 发布于2025-02-06
  • 现代游戏开发人员的高级JavaScript游戏开发技术
    现代游戏开发人员的高级JavaScript游戏开发技术
    使用JavaScript构建游戏比以往任何时候都更令人兴奋。无论您是在编码经典平台游戏还是复杂的模拟,都知道如何充分利用工具,可以改变游戏规则。本指南深入研究了JavaScript游戏开发的基本策略和高级技术,这些技术可以帮助您提高自己的技巧。 1。游戏开发中的网络工作者 为什么要使...
    编程 发布于2025-02-06
  • 如何修复\“常规错误:2006 MySQL Server在插入数据时已经消失\”?
    如何修复\“常规错误:2006 MySQL Server在插入数据时已经消失\”?
    插入记录时如何解决“一般错误:2006 MySQL 服务器已消失”介绍:将数据插入 MySQL 数据库有时会导致错误“一般错误:2006 MySQL 服务器已消失”。当与服务器的连接丢失时会出现此错误,通常是由于 MySQL 配置中的两个变量之一所致。解决方案:解决此错误的关键是调整wait_tim...
    编程 发布于2025-02-06
  • 在映射到MySQL枚举列时,如何确保冬眠保留值?
    在映射到MySQL枚举列时,如何确保冬眠保留值?
    在hibernate中保存枚举值:故障排除错误的列type ,他们各自的映射至关重要。在Java中使用枚举类型时,至关重要的是,建立冬眠的方式如何映射到基础数据库。在您的情况下,您已将MySQL列定义为枚举,并在Java中创建了相应的枚举代码。但是,您遇到以下错误:“ MyApp中的错误列类型。...
    编程 发布于2025-02-06
  • 我可以在CSS中使用SVG作为伪元素吗?
    我可以在CSS中使用SVG作为伪元素吗?
    使用svgs用作pseudo-element content css content properts允许在使用元素之前或之后使用元素插入各种类型的内容伪元素,例如::之前和::之后。但是,对可以包括哪些内容有限制。可以将svgs用作pseudo-element Content?,现在可以使用s...
    编程 发布于2025-02-06
  • 对象拟合:IE和Edge中的封面失败,如何修复?
    对象拟合:IE和Edge中的封面失败,如何修复?
    解决此问题,我们采用了一个巧妙的CSS解决方案来解决问题:高度:100%; 高度:auto; 宽度:100%; //对于水平块 ,使用绝对定位将图像定位在中心,以object-fit:object-fit:cover in IE和edge消除了问题。现在,图像将按比例扩展,保持所需的效果而不会失...
    编程 发布于2025-02-06

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

Copyright© 2022 湘ICP备2022001581号-3