RadAjaxManager 的正确配置是什么 - 这个问题与 UpdatePanel 相关!

发布于 2024-08-30 07:07:28 字数 6529 浏览 4 评论 0原文

首先看下面的aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Amlak.WebForm4" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="CheckBox1" UpdatePanelRenderMode="Inline" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" AppendDataBoundItems="True"
            OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
            </Items>
        </telerik:RadComboBox>
        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
            Text="Check Me" TextAlign="Left" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

我的后台代码是这样的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Amlak
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (RadComboBox1.SelectedItem.Value == "2")
            {
                CheckBox1.Checked = true;
            }
            else
            {
                CheckBox1.Checked = false;
            }

        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox1.Checked)
            {
                TextBox1.Text = "text";
            }
            else
            {
                TextBox1.Text = "";
            }
        }
    }
}

我的目标:

  1. 我想强制RadComboBox1在AJAX模式下工作,并通过后台代码中定义的条件更改CheckBox1.Checked 。 ->不想为此回发。

  2. 我想强制 CheckBox1 在 PostBack 模式下工作,并通过代码隐藏中定义的条件更改 TextBox1.text。 ->我想对此进行回发。

在这种情况下-> RadComboBox1 工作正常
但我不知道为什么当我们更改 CheckBox1 的检查时 OnCheckedChanged="CheckBox1_CheckedChanged" 不会触发! (因为我们将其添加为 RadAjaxManager1RadComboBox1 的更新)。


我的问题:

我是否应该添加 RadComboBox1 作为 RadComboBox1 的更新?不过,不添加这个也能正常工作。

如果我们将 ChechBox1 添加到 RadAjaxManager1 中,如下所示:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Amlak.WebForm4" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="CheckBox1" UpdatePanelRenderMode="Inline" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="CheckBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="TextBox1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" AppendDataBoundItems="True"
            OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
            </Items>
        </telerik:RadComboBox>
        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
            Text="Check Me" TextAlign="Left" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

因此它在 AJAX 模式下工作正常,但我想强制 CheckBox1 在 PostBack 中工作!< br> 我该如何解决这个问题?

我是否应该添加 TextBox1 作为 RadAjaxManagerRadComboBox1 的更新?

感谢您关注我的问题。 此致

At first look at the below aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Amlak.WebForm4" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="CheckBox1" UpdatePanelRenderMode="Inline" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" AppendDataBoundItems="True"
            OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
            </Items>
        </telerik:RadComboBox>
        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
            Text="Check Me" TextAlign="Left" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

My code behind is like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Amlak
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (RadComboBox1.SelectedItem.Value == "2")
            {
                CheckBox1.Checked = true;
            }
            else
            {
                CheckBox1.Checked = false;
            }

        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox1.Checked)
            {
                TextBox1.Text = "text";
            }
            else
            {
                TextBox1.Text = "";
            }
        }
    }
}

My goals:

  1. I want to force RadComboBox1 to work in AJAX mode and change the CheckBox1.Checked by defined conditions in code behind. -> do not want postback for this.

  2. I want to force CheckBox1 to work in PostBack mode and change the TextBox1.text by defined conditions in code behind. -> I want postback for this.

In this scenario -> RadComboBox1 works fine
but I don't know why OnCheckedChanged="CheckBox1_CheckedChanged" does not fire when we change check of CheckBox1! (because we added it as update of RadComboBox1 In RadAjaxManager1).


My questions:

Should I add RadComboBox1 as update Of RadComboBox1 or not? However it works fine without adding this.

If we add ChechBox1 To RadAjaxManager1 like below:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Amlak.WebForm4" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="CheckBox1" UpdatePanelRenderMode="Inline" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="CheckBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="TextBox1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" AppendDataBoundItems="True"
            OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
            </Items>
        </telerik:RadComboBox>
        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
            Text="Check Me" TextAlign="Left" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

So it works fine in AJAX mode, but I want to force CheckBox1 to work in PostBack!
How can I fix this issue?

Should I add TextBox1 as update of RadComboBox1 in RadAjaxManager or not?

Thanks for attention to my question.
best regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2024-09-06 07:07:28

当前 RadAjax 限制 说,

RadAjaxManager 设置不会使用 ajax 按钮...
...没有更新的控件时

因此,您可能必须执行以下操作:

<UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="ChechBox1" />
</UpdatedControls>

Current RadAjax Limitations says,

RadAjaxManager setting will not ajaxify the button...
...when having no updated controls

So, you probably will have to do something like:

<UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="ChechBox1" />
</UpdatedControls>
澜川若宁 2024-09-06 07:07:28

您甚至可以利用 RadAjaxManager 的 OnRequestStart 来禁用特定请求的 Ajax 功能。这是您的代码的更新版本,可按您的要求工作:

<div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl
                        ControlID="CheckBox1"
                        UpdatePanelRenderMode="Inline" />
                    <telerik:AjaxUpdatedControl
                        ControlID="TextBox1"
                        UpdatePanelRenderMode="Inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="CheckBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl
                        ControlID="TextBox1"
                        UpdatePanelRenderMode="Inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
        <ClientEvents OnRequestStart="onAjaxRequestStart" />
    </telerik:RadAjaxManager>

    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        AutoPostBack="True"
        AppendDataBoundItems="True"
        OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
            <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
            <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
            <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
        </Items>
    </telerik:RadComboBox>

    <br />
    <br />

    <asp:CheckBox ID="CheckBox1" runat="server"
        AutoPostBack="True"
        OnCheckedChanged="CheckBox1_CheckedChanged"
        Text="Check Me"
        TextAlign="Left" />

    <br />
    <br />

    <asp:TextBox ID="TextBox1" runat="server" />

    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function onAjaxRequestStart(s, e) {
                var target = e.get_eventTarget(),
                    checkBoxId = '<%= CheckBox1.ClientID %>';
                if (target === checkBoxId) {
                    e.set_enableAjax(false);
                }
            }
        </script>
    </telerik:RadCodeBlock>
</div>

You can take advantage of the OnRequestStart even of the RadAjaxManager to disable Ajax functionality for specific requests. Here's an updated version of your code that works as you requested:

<div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadComboBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl
                        ControlID="CheckBox1"
                        UpdatePanelRenderMode="Inline" />
                    <telerik:AjaxUpdatedControl
                        ControlID="TextBox1"
                        UpdatePanelRenderMode="Inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="CheckBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl
                        ControlID="TextBox1"
                        UpdatePanelRenderMode="Inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
        <ClientEvents OnRequestStart="onAjaxRequestStart" />
    </telerik:RadAjaxManager>

    <telerik:RadComboBox ID="RadComboBox1" runat="server"
        AutoPostBack="True"
        AppendDataBoundItems="True"
        OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
            <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
            <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
            <telerik:RadComboBoxItem runat="server" Text="4" Value="4" />
        </Items>
    </telerik:RadComboBox>

    <br />
    <br />

    <asp:CheckBox ID="CheckBox1" runat="server"
        AutoPostBack="True"
        OnCheckedChanged="CheckBox1_CheckedChanged"
        Text="Check Me"
        TextAlign="Left" />

    <br />
    <br />

    <asp:TextBox ID="TextBox1" runat="server" />

    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function onAjaxRequestStart(s, e) {
                var target = e.get_eventTarget(),
                    checkBoxId = '<%= CheckBox1.ClientID %>';
                if (target === checkBoxId) {
                    e.set_enableAjax(false);
                }
            }
        </script>
    </telerik:RadCodeBlock>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文