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

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]删除
最新教程 更多>
  • Hexabot 设置和可视化编辑器教程:构建您的第一个 AI 聊天机器人
    Hexabot 设置和可视化编辑器教程:构建您的第一个 AI 聊天机器人
    聊天机器人爱好者大家好!在本教程中,我们将指导您完成设置和使用开源 AI 聊天机器人构建器 Hexabot 的过程。我们将首先克隆 GitHub 存储库、安装依赖项并为 Hexabot 配置环境变量。您还将学习如何使用 Docker 启动项目、访问管理面板以及使用可视化编辑器创建聊天机器人流程。 在...
    编程 发布于2024-11-02
  • mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_array():您应该选择哪一个?
    mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_array():您应该选择哪一个?
    mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_array() 解释背景:如果您正在使用已弃用的MySQL 扩展中,在从结果集中检索数据的 mysql_fetch_row()、mysql_fetch_assoc() 和 mysql_fetch_...
    编程 发布于2024-11-02
  • Next.js - 概述
    Next.js - 概述
    本文作为初学者友好的指南和使用 Next.js 的步骤。 Next.js 是一个用于构建 Web 应用程序的灵活框架。相反,它是一个构建在 Node.js 之上的 React 框架。 设置您的 Next.js 项目 要启动新的 Next.js 项目,您需要在计算机上安装 Node.js。 安装 安装...
    编程 发布于2024-11-02
  • 如何在代码中使用 Unsplash 图片
    如何在代码中使用 Unsplash 图片
    作为一名从事新 SaaS 项目的开发人员,我需要直接通过 URL 链接一些 Unsplash 图像。 最初,我看到一篇推荐使用 https://source.unsplash.com/ API 的文章(链接)。但是,此方法不再有效,并且仅从 URL 字段复制链接并不能提供嵌入所需的直接图像 URL...
    编程 发布于2024-11-02
  • 如何合并关联数组、处理缺失键以及填充默认值?
    如何合并关联数组、处理缺失键以及填充默认值?
    合并多个关联数组并添加具有默认值的缺失列将关联数组与不同的键集组合起来创建统一的数组可能具有挑战性。这个问题探索了一种实现此目的的方法,所需的输出是一个数组,其中键被合并,缺失的列用默认值填充。为了实现这一点,建议结合使用 array_merge 函数精心设计的键数组:$keys = array()...
    编程 发布于2024-11-02
  • 通过 testcontainers-go 和 docker-compose 来利用您的测试套件
    通过 testcontainers-go 和 docker-compose 来利用您的测试套件
    Welcome back, folks! Today, we will cover the end-to-end tests in an intriguing blog post. If you've never written these kinds of tests or if you stri...
    编程 发布于2024-11-02
  • 以下是一些适合您文章的基于问题的标题:

**直接简洁:**

* **如何在Windows控制台中正确显示UTF-8字符?**
* **为什么传统方法无法显示
    以下是一些适合您文章的基于问题的标题: **直接简洁:** * **如何在Windows控制台中正确显示UTF-8字符?** * **为什么传统方法无法显示
    在 Windows 控制台中正确显示 UTF-8 字符使用传统方法在 Windows 控制台中显示 UTF-8 字符的许多尝试均失败正确渲染扩展字符。失败的尝试:使用 MultiByteToWideChar() 和 wprintf() 的一种常见方法被证明是无效的,只留下 ASCII 字符可见。此外...
    编程 发布于2024-11-02
  • ReactJS 的模拟介绍
    ReactJS 的模拟介绍
    ReactJS 19:重要部分 并发模式增强: ReactJS 19 中最大的改进是并发模式,它不仅在应用程序自身更新时保持 UI 平滑和响应灵敏,而且还确保了无缝界面,尤其是在复杂的过渡(例如动画)时。 改进的服务器组件: 在 Python 的引领下,ReactJ...
    编程 发布于2024-11-02
  • 首届DEV网页游戏挑战赛评委
    首届DEV网页游戏挑战赛评委
    我被要求对DEV团队9月份组织的第一届网页游戏挑战赛提交的参赛作品进行评判,结果在10月初发布。 我们几个月来一直在 DEV 上组织挑战(迷你黑客马拉松),并计划宣布我们的第一个网页游戏挑战。鉴于您在游戏社区 和 dev.to 的专业知识和参与度,我们想知道您是否有兴趣成为客座评委。 谁能对此说“不...
    编程 发布于2024-11-02
  • 购买经过验证的现金应用程序帐户:安全可靠的交易
    购买经过验证的现金应用程序帐户:安全可靠的交易
    Buying verified Cash App accounts is not recommended. It can lead to security risks and potential account bans. If you want to more information just k...
    编程 发布于2024-11-02
  • 为什么 `std::function` 缺乏相等比较?
    为什么 `std::function` 缺乏相等比较?
    揭开 std::function 的等式可比性之谜难题:为什么是 std::function,现代 C 代码库的一个组成部分,不具备相等比较功能?这个问题从一开始就困扰着程序员,导致管理可调用对象集合的混乱和困难。早期的歧义:在 C 语言的早期草案中11 标准中,operator== 和operat...
    编程 发布于2024-11-02
  • JavaScript 类型检查 |编程教程
    JavaScript 类型检查 |编程教程
    介绍 本文涵盖以下技术技能: 在本实验中,我们将探索一个 JavaScript 函数,该函数检查提供的值是否属于指定类型。我们将使用 is() 函数,它利用构造函数属性和 Array.prototype.includes() 方法来确定值是否属于指定类型。本实验将帮助您更好地了解 ...
    编程 发布于2024-11-02
  • 使用 Streamlit 将机器学习模型部署为 Web 应用程序
    使用 Streamlit 将机器学习模型部署为 Web 应用程序
    介绍 机器学习模型本质上是一组用于进行预测或查找数据模式的规则或机制。简单地说(不用担心过于简单化),在 Excel 中使用最小二乘法计算的趋势线也是一个模型。然而,实际应用中使用的模型并不那么简单——它们通常涉及更复杂的方程和算法,而不仅仅是简单的方程。 在这篇文章中,我将首先构...
    编程 发布于2024-11-02
  • ## utf8_unicode_ci 与 utf8_bin:哪种 MySQL 排序规则最适合德国网站?
    ## utf8_unicode_ci 与 utf8_bin:哪种 MySQL 排序规则最适合德国网站?
    为德语选择最佳 MySQL 排序规则在设计为德语受众量身定制的网站时,支持像 ä、 ü 和 ß。当涉及特定于语言的要求时,排序规则的选择起着重要作用。字符集和排序规则对于字符处理,UTF-8 仍然是首选选项,提供广泛的字符支持。至于排序规则,需要考虑德语特定字符。排序规则类型MySQL 提供各种排序...
    编程 发布于2024-11-02
  • 异常处理基础知识
    异常处理基础知识
    Java中的异常处理由五个关键字管理:try、catch、 throw、throws和finally。 这些关键字构成了一个相互关联的子系统。 要监视的指令位于 try 块内。 如果try块中发生异常,则会抛出异常。 代码可以使用catch捕获并处理异常。 系统异常由Java运行时自动抛出。 要手...
    编程 发布于2024-11-02

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

Copyright© 2022 湘ICP备2022001581号-3