繁体   English   中英

UpdatePanel中ASP TextBox上的AutoPostBack不起作用

[英]AutoPostBack on ASP TextBox in UpdatePanel not working

我在设置背景色的窗体上有一个带有ColorPickerExtender的TextBox控件。 我希望用户更改颜色时会发生两件事:

  • 控件的颜色改变
  • 我收到了即时AJAX事件,因此可以在页面的其他部分进行更改

使用onColorChanged() JavaScript可以很好地进行颜色更改。 我的事件处理程序还会在从其他控件生成的完整回发和部分/ AJAX回发期间触发。 但是,它本身不会立即生成回发。

这是.aspx文件的相关行:

<%@ Page Title="" Language="C#" MasterPageFile="~/FingerTipDisplay.Master" AutoEventWireup="true" CodeBehind="EditorLayoutv3.aspx.cs" Inherits="FingerTipDisplay.config.EditorLayoutv3" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit" %>



<asp:UpdatePanel ID="upGeneralLayoutData" runat="server">
    <ContentTemplate>
        <asp:Label runat="server" Text="Background color:" CssClass="ContentBodyText" ToolTip="Select the background color for this layout"></asp:Label>
        <asp:TextBox ID="txtLayoutBackgroundColor" runat="server" ToolTip="Select the background color for this layout" CssClass="ColorPickerExtenderTextBox" Width="50" OnTextChanged="txtLayoutBackgroundColor_TextChanged" AutoPostBack="True"></asp:TextBox>
        <ajaxControlToolkit:ColorPickerExtender TargetControlID="txtLayoutBackgroundColor" runat="server"  OnClientColorSelectionChanged="onColorChanged" />
    </ContentTemplate>
</asp:UpdatePanel>

这是来自站点主站的ScriptManager:

<asp:ScriptManager ID="smFingerTipDisplay" runat="server">
</asp:ScriptManager>

这是事件处理程序:

protected void txtLayoutBackgroundColor_TextChanged(object sender, EventArgs e)
{
    moLayout.BackgroundColor = txtLayoutBackgroundColor.Text;

    if (moLayout.BackgroundColor.Substring(0, 1) != "#")
    {
        moLayout.BackgroundColor = "#" + moLayout.BackgroundColor;
    }

    // TODO: update preview image
}

这是JavaScript:

onColorChanged = function (oSender) {
    /// <summary>Callback to use for when a color picker extender changes colors.  This
    /// sets the foreground and background of the TextBox control to the selected color.
    /// <param name='oSender' type='Object'>The control that changed</param>
    oSender.get_element().style.color = "#" + oSender.get_selectedColor();
    oSender.get_element().style.backgroundColor = "#" + oSender.get_selectedColor();
}

解决了问题。 事实证明,当ColorPickerExtender更改相应TextBox中的TextBox它根本不会引发TextChanged事件。 但是,手动输入TextBox产生所需的效果,因此我将其添加到onColorChanged处理程序中:

oSender.get_element().onchange();

现在可以了。 感谢大家的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM