Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I set focus to a textbox inside a Gridview Footer inside an UpdatePanel?

Posted on 2009-07-02
3
Medium Priority
?
2,480 Views
Last Modified: 2013-12-17
I am using a footer in a GridView to "add" items to the gridview via a textbox and button combination and the GridView is inside an UpdatePanel.  That's working fine.  

What I would like to do is have the textbox receive focus after the partial page update.  How can I do that?

Is there an event on the UpdatePanel I can capture/code that will do this?
<asp:UpdatePanel ID="upnlEditUsers" runat="server">             
            <ContentTemplate>             
                <asp:Panel ID="pnlUsers" runat="server" Height="300" style="text-align:left;">                     
                    <asp:GridView ID="gvUsers" runat="server"                              
                            CellPadding="3"  CellSpacing="0"
                            Width="350px" 
                            PagerStyle-HorizontalAlign="center"                          
                            AutoGenerateColumns="false"                                                                                
                             ShowFooter="true"
                            ShowHeader="true" 
                            OnRowCommand="gvUsers_RowCommand" 
                            DataKeyNames="PersonID, RequestID" 
                            OnRowDataBound="gvUsers_RowDataBound" 
                        >
                        <AlternatingRowStyle CssClass="altRowStyle" />
                        <RowStyle CssClass="RowStyle" />
                        <HeaderStyle CssClass="HeaderStyle" />
                        <SelectedRowStyle CssClass="SelectedRowStyle" />
                        <PagerStyle CssClass="PagerStyle" />                                                        
                        <EmptyDataRowStyle />                    
                        <Columns>                                             
                            <asp:TemplateField HeaderText="User(s)"  ItemStyle-HorizontalAlign="Left">
                                <ItemTemplate>
                                    <asp:Label ID="lblUserFullName" runat="server" Text='<%# Bind("UserFullName") %>'></asp:Label> 
                                </ItemTemplate>                           
                               <FooterTemplate>
                                    <asp:TextBox ID="tbxPersonSearch" runat="server" ></asp:TextBox>                                                                 
                                    <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="3"
                                        TargetControlID="tbxPersonSearch"                      
                                        ServiceMethod="PersonSearchLastName" ServicePath="~/WebServices/AutoComplete.asmx"                     
                                        CompletionSetCount="30"
                                        OnClientItemSelected="PersonSearchItemSelected" 
                                        FirstRowSelected="false"
                                        >                                                                                       
                                    </cc1:AutoCompleteExtender> 
                                    <asp:Button ID="btnAddPersonToRequest" Text="Add" runat="server" OnClick="btnAddPersonToRequest_Click" OnClientClick="javascript:EnableValidators(false);" />
                               </FooterTemplate>
                            </asp:TemplateField>                           
                            <asp:TemplateField HeaderStyle-BorderColor="#CCCCCC" ItemStyle-BorderColor="#CCCCCC"
                                    ItemStyle-HorizontalAlign="center" Visible="true">
                                    <ItemTemplate>
                                        <asp:ImageButton AlternateText="Remove User" ID="btnRemoveUser" ImageUrl="~/Images/delete.ico"
                                            CausesValidation="false" CommandName="Remove" CommandArgument='<%# Bind("PersonID") %>'
                                            runat="server" />
                                    </ItemTemplate>
                            </asp:TemplateField>                                
                        </Columns>              
                        <EmptyDataTemplate> 
                            <div style="margin: 5px 5px 5px;" ><asp:Label ID="lblNoUsers" Text="There are no users associated with this request." runat="server"></asp:Label></div>
                            <asp:TextBox ID="tbxPersonSearch" style="margin-left: 5px;" runat="server"  ></asp:TextBox>                                                                 
                                    <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="3"
                                        TargetControlID="tbxPersonSearch"                      
                                        ServiceMethod="PersonSearchLastName" ServicePath="~/WebServices/AutoComplete.asmx"                     
                                        CompletionSetCount="30"
                                        OnClientItemSelected="PersonSearchItemSelected" 
                                        FirstRowSelected="true"
                                        >                                                                                       
                                    </cc1:AutoCompleteExtender> 
                                    <asp:Button ID="btnAddPersonToRequest" Text="Add" runat="server" OnClick="btnAddPersonToRequest_Click" />
                        </EmptyDataTemplate>                    
                    </asp:GridView>                                        
               </asp:Panel>
             </ContentTemplate>  
           </asp:UpdatePanel>

Open in new window

0
Comment
Question by:Bruce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
G0ggy earned 1000 total points
ID: 24763603
Try this:

<script language="JavaScript" type="text/javascript">
function doSomething() {
 if (request.readyState == 4) {
  form1.txtInput2.focus();
  }
 }
</script>
0
 
LVL 3

Assisted Solution

by:Dov_Landau
Dov_Landau earned 1000 total points
ID: 24764761
You can use UpdatePanel.Load Event. Something like the code below:
Please Notice that you should use the ScriptManager.SetFocus Method!

<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="MyUpdatePanel" runat="server" onload="MyUpdatePanel_Load">
            <ContentTemplate>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="MyButton" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        
        <asp:Button ID="MyButton" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="äê× çÕÑå" OnClick="btnPrint_Click" />
    </div>
    </form>
</body>
 
and here is the c# Code.
========================
   protected void MyUpdatePanel_Load(object sender, EventArgs e)
    {
        ScriptManager1.SetFocus(TextBox1);
    }

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question