ModalPopupExtender

Last post 07-02-2009 11:07 PM by chetan.sarode. 3 replies.

Sort Posts:

  • ModalPopupExtender

    07-01-2009, 9:16 AM
    • Member
      1 point Member
    • saurabh.15in
    • Member since 10-01-2007, 5:52 AM
    • Posts 32

     Hi ,

    I am having a problem.

    in my page i have a ModalPopupExtender in which i have a textbox.

    when user click on new button.this modelpopextender open and textbox is focused.

    I am using below code to do this.

    mpeNewCompany.Show()

    txtNewCompany.Focus()

    Up to here..code is running fine.

    Not i have another page and from that page i am navigating to this page which is having modelpopup.

    i am checking on page load, if the page is redirecting from that page, then whithout clicking on new, i am prompting modelpopupextender.This is also working fine.

    But i want when the model popup get open , the focus should be on textbox.This is not happening. I am using the same code for focus. Below is the code which i am calling at Page load.

    Private Sub

    CheckNewEdit()

    Try

    'If company Id is 0 then it is redirected to add new company

    'otherwise this page has been redirected to edit records of existing company

    If CompanyId = "0"

    Then

    ibtnPrint.Enabled =

    False

    ibtnReferesh.Enabled =

    False

    ibtnSave.Enabled =

    False

    cmdNew.Enabled =

    True

    If Not IsPostBack

    Then

    mpeNewCompany.Show()

    txtNewCompany.Text =

    ""

    lblNewError.Text =

    ""

    txtNewCompany.Focus()

    End

    If

    Else

    ibtnPrint.Enabled =

    True

    ibtnReferesh.Enabled =

    True

    ibtnSave.Enabled =

    True

    cmdNew.Enabled =

    True

    End

    If

    Catch ex As

    Exception

    ShowError(

    "An error occurred CheckNewEdit: "

    & ex.Message)

    End

    Try

    End

    Sub

    ----------------------------------------

     

     

    Please help.

    Thanks in advance.

    Saurabh

  • Re: ModalPopupExtender

    07-01-2009, 9:40 AM
    • Participant
      856 point Participant
    • stlarmon
    • Member since 06-10-2008, 9:56 PM
    • New York, USA
    • Posts 144

    I've noticed that sometimes calling focus on a control when using AJAX doesn't always work.  I've always had success using the Scriptmanager to set focus

    ScriptManager.GetCurrent(Me.Page).SetFocus(txtNewCompany)


     

    Steve
  • Re: ModalPopupExtender

    07-02-2009, 2:37 AM
    • Member
      42 point Member
    • net.ninjutsu
    • Member since 07-01-2009, 8:08 AM
    • Posts 11

    saurabh.15in what strlarmon suggested you should help.

    Generally Control.Focus will cause when page renders register script that will fire <your control client id>.focus() script.

    However when using ajax this script will be executed beofre $create's of any IScriptControl is evaluated, thus your control which lives inside the popup is not yet created and <your control client id>.focus() does nothing. ScriptManager method does essentially same thing except that this will be executed when all the scripts are fully loaded and your control is already on the page.

    This will do the trick for you ;)

  • Re: ModalPopupExtender

    07-02-2009, 11:07 PM
    Answer

    To set focus and select text of a you have to use the following:
     

    ScriptManager.RegisterStartupScript(this, this.GetType(), "selectAndFocus", "$get('" + myTextBox.ClientID + "').focus();$get('" + myTextBox.ClientID + "').select();", true);
    http://forums.asp.net/t/1099345.aspx
    http://forums.asp.net/t/1199709.aspx

      http://forums.asp.net/t/1131786.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (4 items)