2011-05-04 43 views
1
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Always" > 
<ContentTemplate> 
<asp:Timer ID="Timer1" runat="server" Interval="300" ontick="Timer1_Tick"></asp:Timer> 
</ContentTemplate> 
</asp:UpdatePanel> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" > 
<ContentTemplate> 
</ContentTemplate> 
</asp:UpdatePanel> 

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> 
<ContentTemplate> 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Send" /> 
</ContentTemplate> 
</asp:UpdatePanel> 


問題是,TextBox1’s光標不閃爍它是靜態的,但你可以寫在它。它給人的印象是凍結。爲什麼光標不閃爍?的UpdatePanel,定時器和TexBox問題

+0

切換焦點可能會解決這個問題。您是否嘗試將JavaScript用於「TextBox1.blur()」和「TextBox1.focus()」? – 2011-05-04 21:25:20

+0

我會以答案的形式發佈,但我不確定它是否是您要找的。 – 2011-05-04 22:13:52

+0

你試試吧 - 你已經有了所有必要的代碼。 ;-) – 2011-05-04 22:20:16

回答

1

您應該將您的計時器間隔設置爲接近1000毫秒。這應該解決你的閃爍問題。

0

回發完成後,您可以運行一段JavaScript,它將從文本框中移除焦點(例如,它將不再接受文本),然後您可以立即重新對焦文本框(因此它會接受文本再次)。這可能會「重置」光標,使其正確顯示。

嘗試添加以下內容到ASPX,最好外的UpdatePanel的:

<script type="text/javascript"> 
    function fixTextBoxFocus() 
    { 
     var textBox = document.getElementById("<%= TextBox1.ClientID %>"); 

     textBox.blur(); //Remove the focus from the text box. 
     textBox.focus();//Re-focus on the textbox. 
    } 
</script> 

,然後在你的代碼隱藏(與你的頁面的類的名稱替換MyPage):

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    this.ClientScript.RegisterStartupScript(typeof(MyPage), "fixTextBoxFocus", "fixTextBoxFocus();", true); 
} 

現在,當部分後貼片發生時,每次都會執行此腳本。嘗試一下,讓我知道它是否有助於解決問題。

+0

對不起,它沒有奏效。遊標仍然是靜態的,不閃爍。我認爲這是由於'Timer'。 – jams 2011-05-04 22:29:02

0

在updatepanel內放置一個定時器將導致該更新面板的重複刷新。即使您已將計時器時間間隔設置爲300毫秒。這可能是問題所在。 您需要考慮的事項 - 您是否真的想將計時器放置在更新面板中? 你真的需要保持300毫秒的時間間隔。 將不可能將文本框移動到updatepanel之外嗎?

+0

我已將'Timer'放入其他'UpdatePanel'中,而不是'TextBox'' UpdatePanel'中。所以'定時器'的刷新不應該干擾'TextBox'。 – jams 2011-05-04 22:48:12