Domanda

In un primo sguardo al di sotto 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>

Il mio codice dietro è come questo:

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 = "";
            }
        }
    }
}

I miei obiettivi:

  1. Voglio forza RadComboBox1 al lavoro in modalità di AJAX e cambiare il CheckBox1.Checked dalle condizioni definite nel codice dietro. -> non vogliono postback per questo.

  2. Voglio forza CheckBox1 al lavoro in modalità PostBack e cambiare le TextBox1.text dalle condizioni definite nel codice dietro. -> Voglio postback per questo

  3. .

In questo scenario -> RadComboBox1 funziona bene
ma io non so perché OnCheckedChanged="CheckBox1_CheckedChanged" non si attiva quando cambiamo controllo di CheckBox1! (Perché abbiamo aggiunto come aggiornamento RadComboBox1 In RadAjaxManager1).


Le mie domande:

dovrebbe aggiungo RadComboBox1 come aggiornamento RadComboBox1 o no? Tuttavia funziona benissimo senza l'aggiunta di questo.

Se aggiungiamo ChechBox1 Per RadAjaxManager1 come di seguito:

<%@ 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>

Così funziona bene in modalità AJAX, ma voglio forzare CheckBox1 al lavoro in postback!
Come posso risolvere il problema?

dovrebbe aggiungo TextBox1 come aggiornamento RadComboBox1 in RadAjaxManager o no?

Grazie per l'attenzione alla mia domanda. migliori saluti

È stato utile?

Soluzione 2

E 'possibile sfruttare l'OnRequestStart anche del RadAjaxManager per disabilitare la funzionalità Ajax per richieste specifiche. Ecco una versione aggiornata del codice che funziona come da voi richiesto:

<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>

Altri suggerimenti

attuali RadAjax Limitazioni dice,

  

impostazione RadAjaxManager non ajaxify il tasto ...   ... controlla quando non aver aggiornato

Quindi, probabilmente sarà necessario fare qualcosa di simile:

<UpdatedControls>
               <telerik:AjaxUpdatedControl ControlID="ChechBox1" />
</UpdatedControls>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top