How can I prevent a textbox from taking focus on the postback when I have a calendar extender on it?

Posted by Biff MaGriff on Stack Overflow See other posts from Stack Overflow or by Biff MaGriff
Published on 2010-05-27T15:25:54Z Indexed on 2010/05/27 15:31 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

Hello,

I have repeater, inside this repeater is a user control. In my c# codebehind on my user control I dynamically add a textbox and assign a calendar extender to it. Similar to this.

//custom control
protected void Page_Load(object o, EventArgs e)
{
    TextBox tb = new TextBox();
    tb.ID = "myTextBox";
    MaskedEditExtender meeDate = new MaskedEditExtender();
    meeDate.ID = "meeDate";
    meeDate.TargetControlID = this.UniqueID + "$" + tb.ID;
    meeDate.Mask = "99/99/9999";
    meeDate.MaskType = MaskedEditType.Date;
    CalendarExtender ce = new CalendarExtender();
    ce.ID = "ceCalendar";
    ce.TargetControlID = this.UniqueID + "$" + tb.ID;
    this.Controls.Add(tbDate);
    this.Controls.Add(meeDate);
    this.Controls.Add(ce);
}

This works well, however after I postback the textbox takes focus and the calendar extender fires and it looks really.... dumb.

How can I stop this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about AJAX