Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Textbox with CalendarExtender can't get focus

Back to Forum: Tech Off
  • User profile image

    I have this code that get's run during a post back:


    outStr.Append("    var tDate = document.getElementById(" & Me.txtActivityDate.ClientID & ");" & Chr(13))
    outStr.Append("    tDate.focus();" & Chr(13))
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "dateNext", outStr.ToString, True)


    And I get this message:

    Error: ctl00_PageContent_txtActivityDate is not defined
    Source File: http://localhost/IntranetApps/Strategic_Plans/SP_ExpenseEntry.aspx
    Line: 0


    txtActivityDate has a calendarExtender attached to it. Is there a bug with that extender that would do this?

  • User profile image

    In the page source (from the browser) I have this:


    <input type="text" title="Date activity work occured" id="ctl00_PageContent_txtActivityDate" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$txtActivityDate\',\'\')', 0)" name="ctl00$PageContent$txtActivityDate">

  • User profile image
    Sven Groot

    outStr.Append("    var tDate = document.getElementById(" & Me.txtActivityDate.ClientID & ");" & Chr(13))


    The output of that line does not contain any quotes around the argument to getElementById, so ctl00_PageContent_txtActivityDate gets treated as a variable rather than a string.


    Also, using a stringbuilder and then using concatenations when building the arguments is rather ludicrous.


    Change it to:

    outStr.Append("    var tDate = document.getElementById(""")

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.