Ajaxcontroltoolkit watermark extender timer blink

随声附和 提交于 2019-12-11 05:54:01

问题


I've an ASP.NET page on which I've

  1. 1 Timer (Tick event is trigger for update panel)
  2. 1 Update Panel
  3. 1 Label (in Update Panel)
  4. 1 TextBox
  5. 1 WaterMark extender (for TextBox)

The textbox and watermarkextander are out of the updatepanel, there are some other object in page but I am not listing them, the timer don't affect them. When I write something in textbox there is no problem but when the textbox is empty and the watermarkextender is active on timer tick the watermark text is blinking.

What could be the problem ?.

The updatepanel works fine, no other object is affected on timer tick, but somehow the watermark text is blinking.

Could you please help me about this issue ?

asp.net page:

    <script type="text/javascript">
    Sys.Application.add_load(function () {
        WebForm_OnSubmit = Sys.Extended.UI.TextBoxWatermarkBehavior._originalWebForm_OnSubmit;
    });
</script>


    <div>
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <ajaxToolkit:TextBoxWatermarkExtender ID="TextBox1_TextBoxWatermarkExtender" 
            runat="server" Enabled="True" TargetControlID="TextBox1" 
            WatermarkText="Some Text">
        </ajaxToolkit:TextBoxWatermarkExtender>

        <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
        </asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
        </asp:UpdatePanel>

    </div>

CodeBehind:

protected void Timer1_Tick(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToLongTimeString();
}

回答1:


This is by design feature of WatermarkExtender control. The reason of such behavior is to prevent submitting watermark text to server as value of target textbox.

You can avoid such behavior with adding script below AFTER ScriptManager control:

<script type="text/javascript">
     Sys.Application.add_load(function () 
     {
          WebForm_OnSubmit = Sys.Extended.UI.TextBoxWatermarkBehavior._originalWebForm_OnSubmit;
     });
</script>

Be warned though, that in this case you need explicitly ignore watermarked textboxes values on server if it equals to the watermark text.



来源:https://stackoverflow.com/questions/12367813/ajaxcontroltoolkit-watermark-extender-timer-blink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!