Modal Popup - on show

Last post 06-07-2007 8:47 AM by Rjb23. 16 replies.

Sort Posts:

  • Modal Popup - on show

    01-26-2007, 2:37 PM
    • Loading...
    • codegalaxy
    • Joined on 06-29-2004, 5:00 PM
    • Topeka (Alma), Kansas
    • Posts 1,475
    Is there some script I can run when the modal popup is shown so I can automatically set focus to a control on it
    Dylan Barber
    Dylan's Blog

  • Re: Modal Popup - on show

    01-26-2007, 4:20 PM
    • Loading...
    • Jason Hill
    • Joined on 04-23-2006, 3:39 AM
    • Sydney, Australia
    • Posts 476
    You can hook up a handler to the shown event on the modalpopup that allows you to set the focus: 
    function pageLoad()
    {
        var popup = $find('ModalPopupClientID');
        popup.add_shown(SetFocus);
    }
    
    function SetFocus()
    {
        $get('TextBoxClientID').focus();
    }
    
  • Re: Modal Popup - on show

    02-14-2007, 3:14 PM
    • Loading...
    • tampadotnet
    • Joined on 12-03-2006, 6:04 PM
    • Posts 4
    I tired this on a content page and my SetFocus method never gets called. Is there any reason why this wouldn't work in a master page environment?
  • Re: Modal Popup - on show

    02-14-2007, 3:25 PM
    • Loading...
    • tampadotnet
    • Joined on 12-03-2006, 6:04 PM
    • Posts 4
    I should also mention that I am doing a server-side Show() of the ModalPopupExtender. I have verified in the debugger that the add_shown function runs, but the associated function to set the default focus never gets called when the extender is shown. Thanks.
  • Re: Modal Popup - on show

    02-14-2007, 5:10 PM
    Make sure your client-side $get method is using the *client* ID of the target instead of the *server* one - they're different due to the naming container a Master Page adds.
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Modal Popup - on show

    02-14-2007, 5:32 PM
    • Loading...
    • Jason Hill
    • Joined on 04-23-2006, 3:39 AM
    • Sydney, Australia
    • Posts 476
    Put an alert() call into the SetFocus method to confirm whether it is actually being called.
  • Re: Modal Popup - on show

    04-04-2007, 11:29 AM
    • Loading...
    • zootius
    • Joined on 12-08-2005, 11:00 AM
    • Tadcaster, North Yorkshire, UK
    • Posts 19

    Note that the ModalPopupExtender has a BehaviorID property to give you a javascript object handle:

      

        <ajx:ModalPopupExtender
            ID="ModalWin_Extender"  
            BehaviorID="ModalWin_Extender_ClientObject"
            TargetControlID="lnkNull" 
            PopupControlID="ModalWin"
            runat="server">
        </ajx:ModalPopupExtender>
     

    You then hook up the Client Object's shown() handler to the function of your choice:

     
    $find('ModalWin_Extender_ClientObject').add_shown(jsYourFunction);

     

  • Re: Modal Popup - on show

    04-04-2007, 11:36 AM
    • Loading...
    • zootius
    • Joined on 12-08-2005, 11:00 AM
    • Tadcaster, North Yorkshire, UK
    • Posts 19

    Oh and by the way - server-side, you can set control focus using this:

      

    ScriptManager.GetCurrent(this.Page).SetFocus(txtMyTextBox);
     
     
  • Re: Modal Popup - on show

    04-11-2007, 3:02 AM
    • Loading...
    • Codematic
    • Joined on 11-02-2006, 2:46 PM
    • Posts 42
    zootius:
     

    You then hook up the Client Object's shown() handler to the function of your choice:

     
    $find('ModalWin_Extender_ClientObject').add_shown(jsYourFunction);

     

     

    where do I have to insert this line? In the body: onload() event? 

  • Re: Modal Popup - on show

    04-11-2007, 3:15 AM
    • Loading...
    • Jason Hill
    • Joined on 04-23-2006, 3:39 AM
    • Sydney, Australia
    • Posts 476
    See my post above that shows how you add this to a function called pageLoad that gets called when the page is loaded.
  • Re: Modal Popup - on show

    04-11-2007, 7:59 AM
    • Loading...
    • zootius
    • Joined on 12-08-2005, 11:00 AM
    • Tadcaster, North Yorkshire, UK
    • Posts 19

    Jason's right. Took me a while to realise this too, but Ajax.Net registers some new client-side event handlers, so if you have a javascript function called pageLoad(), it gets called automatically after Ajax.net has finished doing its own onLoad stuff.

     

    More info here: http://ajax.asp.net/docs/overview/AJAXClientEvents.aspx 

  • Re: Modal Popup - on show

    04-25-2007, 7:12 AM
    • Loading...
    • Codematic
    • Joined on 11-02-2006, 2:46 PM
    • Posts 42

    This works perfect for me.

    Thank you very much 

  • Re: Modal Popup - on show

    06-05-2007, 1:51 PM
    • Loading...
    • Rjb23
    • Joined on 10-15-2004, 1:15 PM
    • Posts 57

     I'm having a problem getting this to work, I've tried it and I get an error message.

     Error : Can't move focus to the control because it is invisble, not enabled, or of a type that does not accept focus.

    Here is my code,

    <script type="text/javascript">
    
    
    Sys.Application.add_load(modalSetup);
    function SetFocusOnControl()
    {
        // set the focus with javascript, e.g.: window.getElementById("xyz").focus();
        document.getElementById("txt1").focus();
    }
    function modalSetup()
    {
        var modalPopup = $find('popup1');             // <. this is the BehaviorID from the ModalPopupExtender
        modalPopup.add_showing(SetFocusOnControl);          
    }
    <asp:Button ID="btn1" runat="server" Width="80px" CausesValidation="false"
                        Text=" Swipe Card " Visible="false" />  <asp:Button ID="btnManual" runat="server"
                            Width="90px" Text=" Manual Entry " Visible="false" />               
                    <ajaxToolkit:ModalPopupExtender ID="popup1" runat="server" TargetControlID="btn1"
                        PopupControlID="pnl1" BackgroundCssClass="modalBackground" DropShadow="true" BehaviorID="popup1" />
    <asp:Panel ID="pnl1" runat="server" CssClass="modalPopup" style="display:none;" Width="310">
            <table cellpadding="1" cellspacing="0" width="300" border="0" align="center">						
    				<tr>
    					<td>
    						<textarea rows="1" cols="10" id="txt1" onkeyup="CheckSwipe();" style="color:White;scrollbar-base-color: #FFFFFF;" class="hiddenScrollbars"></textarea>
    					</td>					
    				</tr>
    				
    			</table>
    </asp:Panel>

     

     

  • Re: Modal Popup - on show

    06-05-2007, 5:00 PM
    • Loading...
    • Jason Hill
    • Joined on 04-23-2006, 3:39 AM
    • Sydney, Australia
    • Posts 476

    Try using:

    modalPopup.add_shown(SetFocusOnControl);

    This will fire your function *after* the modalpopup is shown.

  • Re: Modal Popup - on show

    06-06-2007, 8:48 AM
    • Loading...
    • Rjb23
    • Joined on 10-15-2004, 1:15 PM
    • Posts 57

    Thanks, I got it to work. Now I have another problem though. When my popup is shown I have some javascript that runs. The first time it runs fine, but if you hide the popup and show it again and try to run the javascript again it does not run. I don't get any script errors and the script will work fine on a page without the modal popup. Any ideas?

Page 1 of 2 (17 items) 1 2 Next >