Re: Set focus resetting while in update panel and ajax modalpopup

  •  08-31-2009, 10:26 PM

    Re: Set focus resetting while in update panel and ajax modalpopup

    Hi Gilbert,
     
    Try this code, it works fine for me.
     
    1. <%@ Page Language="vb" AutoEventWireup="false" %>   
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    4. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>   
    5. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>   
    6. <html xmlns="http://www.w3.org/1999/xhtml">   
    7. <head id="Head1" runat="server">   
    8.   
    9.     <script type="text/VB" runat="server">      
    10.           
    11.         Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load   
    12.             Page.SetFocus(txtMain)   
    13.         End Sub  
    14.      
    15.         Private Sub btnShow_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnShow.Click   
    16.             modalExtender.Show()   
    17.         End Sub  
    18.        </script>   
    19.   
    20.     <style type="text/css">   
    21.         /*Modal Popup*/.modalBackground   
    22.         {   
    23.             background-color: Gray;   
    24.             filter: alpha(opacity=70);   
    25.             opacity: 0.7;   
    26.         }   
    27.         .modalBox   
    28.         {   
    29.             width: 700px;   
    30.             text-align: center;   
    31.             background-color: #ffffff;   
    32.             padding: 1px 0px;   
    33.         }   
    34.     </style>   
    35.     <title></title>   
    36. </head>   
    37. <body>   
    38.     <form id="form1" runat="server">   
    39.     <asp:ScriptManager ID="scriptMgr" runat="server">   
    40.     </asp:ScriptManager>   
    41.     <asp:UpdatePanel ID="updMain" runat="server" UpdateMode="Conditional">   
    42.         <ContentTemplate>   
    43.             <div>   
    44.                 <asp:TextBox ID="txtMain" runat="server"></asp:TextBox>   
    45.                 <asp:Button ID="btnShow" runat="server" Text="Show popup" OnClientClick="test()" />   
    46.             </div>   
    47.             <asp:Panel ID="pnlPopup" runat="server" Style="display: none;" meta:resourcekey="pnlPopupResource1"  
    48.                 CssClass="modalBox">   
    49.                 <table style="width: 80%;">   
    50.                     <tr>   
    51.                         <td>   
    52.                             <input type="button" value="click" onclick="test()" />   
    53.                             <asp:Label ID="lblName" runat="server" AssociatedControlID="txtName" Text="Name:"  
    54.                                 meta:resourcekey="lblNameResource" />   
    55.                         </td>   
    56.                         <td>   
    57.                             <asp:TextBox ID="txtName" runat="server" MaxLength="100" Style="width: 450px;" />   
    58.                         </td>   
    59.                     </tr>   
    60.                     <tr>   
    61.                         <td>   
    62.                             <asp:Label ID="lblInquiry" runat="server" Text="Message:" meta:resourcekey="lblInquiryResource" />   
    63.                         </td>   
    64.                         <td>   
    65.                             <CE:Editor Width="455" Height="250" ID="ceInquiry" EditorOnPaste="PasteWord" AutoConfigure="Simple"  
    66.                                 runat="server" ShowBottomBar="true" MaxHTMLLength="4000" ShowWordCount="true"  
    67.                                 ShowHtmlMode="true" ShowPreviewMode="false" ShowTagSelector="false">   
    68.                             </CE:Editor>   
    69.                         </td>   
    70.                     </tr>   
    71.                     <tr>   
    72.                         <td style="text-align: right;" colspan="2">   
    73.                             <asp:Button ID="btnCancel" runat="server" CausesValidation="False" Style="width: auto;"  
    74.                                 Text="Cancel" />   
    75.                         </td>   
    76.                     </tr>   
    77.                 </table>   
    78.             </asp:Panel>   
    79.             <asp:Button ID="btnDummy" runat="server" Style="display: none;" meta:resourcekey="btnDummyResource1" />   
    80.             <cc1:ModalPopupExtender ID="modalExtender" runat="server" TargetControlID="btnDummy"  
    81.                 PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" DynamicServicePath=""  
    82.                 Enabled="True"  />   
    83.         </ContentTemplate>   
    84.     </asp:UpdatePanel>   
    85.     </form>   
    86. </body>   
    87. </html>   
    88.   
    89. <script type="text/javascript">   
    90. function CuteEditor_OnInitialized(editor)   
    91. {   
    92.   var txt=document.getElementById('<%= txtName.ClientID%>');   
    93. txt.focus();   
    94. }   
    95. </script>  
    Regards,
     
    Ken
View Complete Thread