在滑块上手动更改值不会更新结果。网络平台

发布于 2024-11-03 07:35:01 字数 4130 浏览 0 评论 0原文

我的问题是这样的:当我在滑块上手动更改值时,即在文本框中输入值而不是拖动滑块,页面不会重新加载,因此看不到任何更改。

我尝试添加“OnTextChanged”监听器,但这不起作用。 我认为设置 AutoPostBack="true" 会导致页面在输入值时重新加载,但这也不起作用。

slidercode:

   <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IntervalSlider.ascx.cs" Inherits="DynamicForm.UserControls.Filter.IntervalSlider" %>
<tr>
<td>
<asp:Label runat="server" ID="lblHeader"></asp:Label><asp:Image runat="server" ID="infoImg" Visible="false" ImageUrl="~/HTML/icons/info_16.png" />
</td>
<td class="filterSpacerCol">&nbsp;</td>
<td>
<table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <asp:TextBox ID="txtMin" size="6" style="text-align:right;" runat="server" AutoPostBack="true" value=""></asp:TextBox>
                            </td>
                            <td width="150px"><div runat="server" id="divSlider" style="margin-top:0px"> <asp:TextBox ID="txtCurrentValue" runat="server" AutoPostBack="true" OnTextChanged="txtCurrentValue_TextChanged" value="20" style="display:none;" />
                                        <ajax:MultiHandleSliderExtender ID="MultiHandleSliderExtenderMinMax" runat="server" Minimum="0" Maximum="10" TargetControlID="txtCurrentValue">
                                            <MultiHandleSliderTargets>
                                                <ajax:MultiHandleSliderTarget ControlID="txtMin" />
                                                <ajax:MultiHandleSliderTarget ControlID="txtMax" />
                                            </MultiHandleSliderTargets>
                                        </ajax:MultiHandleSliderExtender>
                                </div>                                  
                            </td>
                            <td>
                                <asp:TextBox ID="txtMax" size="6" style="text-align:right;" runat="server" AutoPostBack="true" value="" />                                
                            </td>
                        </tr>
                    </table>
</td>       
</tr>   

底层代码:

public partial class IntervalSlider : System.Web.UI.UserControl, IRange
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblHeader.Text = HttpUtility.HtmlEncode(HeaderText);
        if ((ToolTipText ?? "") != "")
        {
            infoImg.Visible = true;
            infoImg.ToolTip = ToolTipText;
            lblHeader.ToolTip = ToolTipText;
        }
        divSlider.Attributes.Add("title", ToolTipText);
        txtMax.ToolTip = ToolTipText;
        txtMin.ToolTip = ToolTipText;            

        foreach (AjaxControlToolkit.MultiHandleSliderTarget target in MultiHandleSliderExtenderMinMax.MultiHandleSliderTargets)
            target.ControlID =  MultiHandleSliderExtenderMinMax.Parent.FindControl(target.ControlID).ClientID;
    }

    public string HeaderText { get; set; }

    public string ToolTipText { get; set; }

    protected void txtCurrentValue_TextChanged(object sender, EventArgs e)
    {
        //FilterChanged(sender, e);
    }

    public event EventHandler FilterChanged;

    public string MaxFilterValue
    {
        get { return txtMax.Text; }
    }

    public int Minimum 
    { 
        get { return MultiHandleSliderExtenderMinMax.Minimum; }
        set 
        { 
            MultiHandleSliderExtenderMinMax.Minimum = value;
            txtMin.Text = value.ToString();
        }
    }

    public int Maximum
    {
        get { return MultiHandleSliderExtenderMinMax.Maximum; }
        set {
            int minValue = value;
            MultiHandleSliderExtenderMinMax.Maximum = minValue;
            txtMax.Text = minValue.ToString();
        }
    }

    public string MinFilterValue
    {
        get { return txtMin.Text; }
    }



}

}

有人知道如何解决这个问题吗?

My problem is this: when I change the values manually on a slider, that is input the value in the textbox instead of dragging the slider, the page is not reloaded so no change is visible.

I've tried adding a "OnTextChanged"-listener but that doesn't work.
I thought setting AutoPostBack="true" would cause the page to reload when inputting values, but that didn't work either.

The slidercode:

   <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IntervalSlider.ascx.cs" Inherits="DynamicForm.UserControls.Filter.IntervalSlider" %>
<tr>
<td>
<asp:Label runat="server" ID="lblHeader"></asp:Label><asp:Image runat="server" ID="infoImg" Visible="false" ImageUrl="~/HTML/icons/info_16.png" />
</td>
<td class="filterSpacerCol"> </td>
<td>
<table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <asp:TextBox ID="txtMin" size="6" style="text-align:right;" runat="server" AutoPostBack="true" value=""></asp:TextBox>
                            </td>
                            <td width="150px"><div runat="server" id="divSlider" style="margin-top:0px"> <asp:TextBox ID="txtCurrentValue" runat="server" AutoPostBack="true" OnTextChanged="txtCurrentValue_TextChanged" value="20" style="display:none;" />
                                        <ajax:MultiHandleSliderExtender ID="MultiHandleSliderExtenderMinMax" runat="server" Minimum="0" Maximum="10" TargetControlID="txtCurrentValue">
                                            <MultiHandleSliderTargets>
                                                <ajax:MultiHandleSliderTarget ControlID="txtMin" />
                                                <ajax:MultiHandleSliderTarget ControlID="txtMax" />
                                            </MultiHandleSliderTargets>
                                        </ajax:MultiHandleSliderExtender>
                                </div>                                  
                            </td>
                            <td>
                                <asp:TextBox ID="txtMax" size="6" style="text-align:right;" runat="server" AutoPostBack="true" value="" />                                
                            </td>
                        </tr>
                    </table>
</td>       
</tr>   

underlying code:

public partial class IntervalSlider : System.Web.UI.UserControl, IRange
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblHeader.Text = HttpUtility.HtmlEncode(HeaderText);
        if ((ToolTipText ?? "") != "")
        {
            infoImg.Visible = true;
            infoImg.ToolTip = ToolTipText;
            lblHeader.ToolTip = ToolTipText;
        }
        divSlider.Attributes.Add("title", ToolTipText);
        txtMax.ToolTip = ToolTipText;
        txtMin.ToolTip = ToolTipText;            

        foreach (AjaxControlToolkit.MultiHandleSliderTarget target in MultiHandleSliderExtenderMinMax.MultiHandleSliderTargets)
            target.ControlID =  MultiHandleSliderExtenderMinMax.Parent.FindControl(target.ControlID).ClientID;
    }

    public string HeaderText { get; set; }

    public string ToolTipText { get; set; }

    protected void txtCurrentValue_TextChanged(object sender, EventArgs e)
    {
        //FilterChanged(sender, e);
    }

    public event EventHandler FilterChanged;

    public string MaxFilterValue
    {
        get { return txtMax.Text; }
    }

    public int Minimum 
    { 
        get { return MultiHandleSliderExtenderMinMax.Minimum; }
        set 
        { 
            MultiHandleSliderExtenderMinMax.Minimum = value;
            txtMin.Text = value.ToString();
        }
    }

    public int Maximum
    {
        get { return MultiHandleSliderExtenderMinMax.Maximum; }
        set {
            int minValue = value;
            MultiHandleSliderExtenderMinMax.Maximum = minValue;
            txtMax.Text = minValue.ToString();
        }
    }

    public string MinFilterValue
    {
        get { return txtMin.Text; }
    }



}

}

Anyone have a clue on how to solve this?

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

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

发布评论

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

评论(1

难得心□动 2024-11-10 07:35:01

我在 IntervalSelector 的页面加载末尾使用这段 JavaScript 代码解决了这个问题:

    string jscript = @"
var filterSearchTimerId = 0; 
var previousFilterValues = new Array();
function SetFilterSearchTimeout ( textBox, executeThis, delayValue ) {
   if (textBox.value == previousFilterValues[textBox.id]) { return; }
   previousFilterValues[textBox.id] = textBox.value;
   if (filterSearchTimerId != 0) { clearTimeout(filterSearchTimerId); }
   filterSearchTimerId = setTimeout(executeThis, delayValue);
}
";

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "SetFilterSearchTimeout", jscript, true);

            string formatString = @"javascript:SetFilterSearchTimeout(this, '__doPostBack(\'{0}\',\'\')', {1})";
            txtMin.Attributes.Add("onkeyup", string.Format(formatString, txtMin.UniqueID, "500"));
            txtMin.Attributes.Add("onpaste", string.Format(formatString, txtMin.UniqueID, "5"));
            txtMin.Attributes.Add("oncut", string.Format(formatString, txtMin.UniqueID, "5"));
            txtMin.Attributes.Add("onchange", string.Format(formatString, txtMin.UniqueID, "0"));

I solved it with this bit of JavaScript-code at the end of the Page Load of the IntervalSelector:

    string jscript = @"
var filterSearchTimerId = 0; 
var previousFilterValues = new Array();
function SetFilterSearchTimeout ( textBox, executeThis, delayValue ) {
   if (textBox.value == previousFilterValues[textBox.id]) { return; }
   previousFilterValues[textBox.id] = textBox.value;
   if (filterSearchTimerId != 0) { clearTimeout(filterSearchTimerId); }
   filterSearchTimerId = setTimeout(executeThis, delayValue);
}
";

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "SetFilterSearchTimeout", jscript, true);

            string formatString = @"javascript:SetFilterSearchTimeout(this, '__doPostBack(\'{0}\',\'\')', {1})";
            txtMin.Attributes.Add("onkeyup", string.Format(formatString, txtMin.UniqueID, "500"));
            txtMin.Attributes.Add("onpaste", string.Format(formatString, txtMin.UniqueID, "5"));
            txtMin.Attributes.Add("oncut", string.Format(formatString, txtMin.UniqueID, "5"));
            txtMin.Attributes.Add("onchange", string.Format(formatString, txtMin.UniqueID, "0"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文