我的问题是:当我手动更改滑块上的值时,即在文本框中输入值而不是拖动滑块,页面不会重新加载,因此看不到任何更改。
我试过添加一个"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"> </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; }
}
}
}
有人知道怎么解决这个问题吗?
我在IntervalSelector的Page Load结尾用这段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"));