2011-04-27 99 views
0

我的問題是這樣的:當我手動更改滑塊上的值時,即在文本框中輸入值而不是拖動滑塊,頁面不會重新加載,因此不會顯示任何更改。在滑塊上手動更改值不會更新結果。 ASP.NET

我試着添加一個「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; } 
    } 



} 

}

人對如何解決這個線索?

回答

0

我與該位的JavaScript的代碼解決它在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"));