k99rs 9 Newbie Poster

I have an application that where i have a an Asp textBox and i added TextBoxWatermarkExtender to it.

<asp:TextBox ID="txtCellNo" runat="Server" /><br />
<ajax:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender4" BehaviorID="CellNoBehavior" TargetControlID="txtCellNo"
    runat="server" WatermarkText="Cell No.">
</ajax:TextBoxWatermarkExtender>

Because i have the page constantly postpage the TextBoxWatermarkExtender Blinds everytime it does a Postback. So i added this to javacript to the page.

function pageLoad() {
    $find('CellNoBehavior')._onSubmit = function () { };
}

The above code prevent it from blinking on every postback. Also this above javascript did not allowed the textBox to PostBack to the code behind when i click the search button. Without the above javascript function i can get the value of the textbox when i click the search button.

I want to get the value of the value of the textbox when i click the button. and also at the have the that when the page postback on an interval of the timer on this page. dont let the watermark blinks.

Can anyone help me out with this? I would really appreciate it.

Dani AI

Generated

— overriding the extender's internal submit handler is fragile: that handler participates in the watermark lifecycle around async posts, so replacing it can stop the normal submit/restore behavior and cause the textbox value not to be sent as expected. A safer pattern is to detect when the Timer (or any specific async trigger) starts an async postback, and only for that case temporarily clear the visible watermark text so it does not "blink", then restore state after the request.

Example approach (replace the placeholder IDs/text with your control ClientIDs or inline <%= ... %> where appropriate):

var prm = Sys.WebForms.PageRequestManager.getInstance();
var hadWatermark = false;

prm.add_initializeRequest(function(sender, args) {
    var initiator = args.get_postBackElement();
    if (!initiator) return;

    // only for timer-initiated async posts: replace with your Timer's client id
    if (initiator.id === 'TIMER_CLIENT_ID') {
        var txt = $get('TEXTBOX_CLIENT_ID');
        if (txt && txt.value === 'WATERMARK_TEXT') {
            txt.value = '';
            hadWatermark = true;
        }
    }
});

prm.add_endRequest(function() {
    if (!hadWatermark) return;
    var txt = $get('TEXTBOX_CLIENT_ID');
    if (txt) {
        txt.value = 'WATERMARK_TEXT';
    }
    hadWatermark = false;
});

If you prefer a server-side safety net, treat the watermark as a non-value in the code behind so a watermark string never becomes meaningful data:

If txtBox.Text.Trim() = "WATERMARK_TEXT" Then
    txtBox.Text = String.Empty
End If

Notes and cautions:

  • Do not rely on private members of the extender; they can change between toolkit versions. Use PageRequestManager events to detect the initiating control and act only for timer/auto-postbacks.
  • If you can target modern browsers, consider HTML5 placeholder instead of the extender (no client-side hacks required).
  • Replace placeholders above with your actual ClientIDs; if you use inline server expressions you can embed them safely into your script.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.