当我设置焦点在按钮上时,焦点自动设置在文本框上 [英] Focus Automatically Set On Text Box While I Set Focus On Button

查看:81
本文介绍了当我设置焦点在按钮上时,焦点自动设置在文本框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

我遇到了问题。我的页面上有文本框。它有HTML编辑器扩展器。我的文本框位于更新面板中。我的页面上也有单选按钮和下拉列表。现在的问题是,当我从下拉菜单或从单选按钮中选择一些东西时,焦点会自动设置在该文本框上,同时我将焦点设置在所选更改上的按钮上。我如何解决这个问题。



在此先感谢。



这是我的代码

Hi Experts,
I am facing a problem .I have text box on my page.which have HTML Editor Extender. My text box is inside Update Panel. I have radio button and drop down list also on my page. now problem is that when i Select some thing from drop down or from radio button the focus automatically set on that text box while i set focus on Button on Selected Change. How i Solve This.

Thanks In Advance.

Here Is My Code

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
<table><tr class="TR1">           
                <td width="20%" style="border: 2px ridge #000000">
                    Impact Categories</td>
                <td colspan="3" style="width: 60%" >
                    <table class="style1" style="border: 2px ridge #000000">
                        <tr>
                            <td width="63%">
                                <asp:DropDownList ID="ddl_ImpCat" runat="server" Width="98%" 
                                    AutoPostBack="True" onselectedindexchanged="ddl_ImpCat1_SelectedIndexChanged">
                                </asp:DropDownList>
                            </td>   
                            <td width="37%"></td>                        
                        </tr>
                        <tr style="height:120px; text-align: left;" >
                            <td colspan="2" >
                                <asp:TextBox ID="txt_ImpCat" runat="server" Rows="5" TextMode="MultiLine" 
                                    Width="98%"  ></asp:TextBox>
                                <asp:HtmlEditorExtender ID="txt_ImpCat_HtmlEditorExtender" runat="server" 
                                    Enabled="True" TargetControlID="txt_ImpCat"  >
                                    <Toolbar ><asp:InsertOrderedList /> </Toolbar>
                                </asp:HtmlEditorExtender>
                            </td>
                        </tr>
                        <tr>
                        <td colspan="2">
                            <asp:Button ID="btn_impCat" runat="server" Text="Add" 
                                onclick="btn_impCat_Click" /></td>
                        </tr>
                        <tr>
                        <td colspan="2">
                        <asp:GridView ID="grid_impCat" runat="server" Width="100%" 
                                AutoGenerateColumns="False" onrowediting="grid_impCat_RowEditing">
                        <Columns>
                         <asp:TemplateField HeaderText="ID" HeaderStyle-HorizontalAlign="Center"  Visible="false">
                         <ItemTemplate>
                         <asp:Label ID="lbl_CIdd" runat="server" Text='<%#Bind("Id_C") %>' ></asp:Label> 
                         <asp:Label ID="lbl_Count" runat="server" Text='<%#Bind("count") %>' ></asp:Label> 
                         <asp:Label ID="lbl_CatId" runat="server" Text='<%#Bind("Cat_Id") %>' ></asp:Label> 
                        </ItemTemplate>
                       <HeaderStyle HorizontalAlign="Left" Width="5%"></HeaderStyle>
                        </asp:TemplateField>
                         <asp:BoundField DataField="Category" HeaderText="Imapct Category" >
                            <HeaderStyle Width="25%" />
                            </asp:BoundField>
                         <asp:TemplateField HeaderText="Description" HeaderStyle-HorizontalAlign="Center" >
                         <ItemTemplate>
                        <asp:Label ID="lbl_CatDescription" runat="server" Text='<%#Bind("Description") %>' ></asp:Label>           
                        </ItemTemplate>
                      <HeaderStyle HorizontalAlign="Left" Width="60%"></HeaderStyle>   </asp:TemplateField>
                          <asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center">
                         <ItemTemplate>
                         <asp:ImageButton ID="imgEdit" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/Images/Edit.gif" Text="Edit" />
                         <asp:Label ID="lbl_edit" runat="server"></asp:Label>
                       </ItemTemplate>   
                        <HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Center" />
                      </asp:TemplateField>
                        </Columns>
                        </asp:GridView>
                        </td>
                        </tr>
                    </table>
                </td>              
            </tr>
            <tr class="TR3">
                <td width="20%">
                    Life of Mine</td>
                <td colspan="3" style="width: 60%">  
                    <table class="style1">
                        <tr>
                            <td width="20%">
                                <asp:RadioButton ID="rbl_Expl" runat="server" Text="Exploration" 
                                    AutoPostBack="True" oncheckedchanged="rbl_Expl_CheckedChanged" />
                            </td>
                            <td width="20%">
                                <asp:RadioButton ID="rbl_Study" runat="server" Text="Study" AutoPostBack="True" 
                                    oncheckedchanged="rbl_Study_CheckedChanged" />
                            </td>
                            <td width="20%">
                                <asp:RadioButton ID="rbl_Constr" runat="server" Text="Construction" 
                                    AutoPostBack="True" oncheckedchanged="rbl_Constr_CheckedChanged" />
                            </td>
                            <td width="20%">
                                <asp:RadioButton ID="rbl_Oper" runat="server" Text="Operation" 
                                    AutoPostBack="True" oncheckedchanged="rbl_Oper_CheckedChanged" />
                            </td>
                            <td width="20%">
                                <asp:RadioButton ID="rbl_Closure" runat="server" Text="Closure" 
                                    AutoPostBack="True" oncheckedchanged="rbl_Closure_CheckedChanged" />
                            </td>
                        </tr>
                    </table>  
                </td>
            </tr>
            <tr class="TR1">
                <td width="20%" style="border: 2px ridge #000000">
                    Risk Rating(No Control)</td>
                <td colspan="3" style="width: 60%">                          
                    <table class="style1" style="border: 2px ridge #000000">
                        <tr>
                            <td width="50%" align="left">
                                Likelihood</td>
                            <td width="50%" align="left">
                                Severity</td>
                        </tr> 
                        <tr>
                            <td width="50%">
                                <asp:DropDownList ID="ddl_RiskRatLik1" runat="server" Width="90%" 
                                    onselectedindexchanged="ddl_RiskRatLik1_SelectedIndexChanged" 
                                    AutoPostBack="True">
                                </asp:DropDownList>
                                </td>
                            <td width="50%">
                                <asp:DropDownList ID="ddl_RiskRatSev1" runat="server" Width="90%" 
                                    onselectedindexchanged="ddl_RiskRatSev1_SelectedIndexChanged" 
                                    AutoPostBack="True">
                                </asp:DropDownList>
                            </td> 
                        </tr>                         
                        <
                        <tr>
                            <td width="50%" id="tb_Risk1"  runat="server" align="center">
                                            <asp:Label ID="lbl_RiskRatLev1" runat="server" Text="" CssClass="style3"></asp:Label>
                                        </td>
                            <td width="50%" id="tb_Risk11"  runat="server" align="center">
                                            <asp:Label ID="lbl_RiskRatRank1" runat="server" Text="" CssClass="style3"></asp:Label>
                                        </td> 
                        </tr>
                        <tr>
                        <td colspan="2">
                            <asp:Button ID="btn_nocontrl" runat="server" Text="Add" 
                                onclick="btn_nocontrl_Click" /></td>
                        </tr>
                        <tr>
                        <td colspan="2">
                        <asp:GridView ID="Grid_Nocontrol" runat="server" Width="100%" 
                                AutoGenerateColumns="False" onrowediting="Grid_Nocontrol_RowEditing">
                        <Columns>
                         <asp:TemplateField HeaderText="ID" HeaderStyle-HorizontalAlign="Center"  Visible="false">
                         <ItemTemplate>
                         <asp:Label ID="lbl_NCIdd" runat="server" Text='<%#Bind("Id_NC") %>' ></asp:Label> 
                         <asp:Label ID="lbl_NoConrolcount" runat="server" Text='<%#Bind("count") %>' ></asp:Label>
                          <asp:Label ID="lbl_NoConrolLik" runat="server" Text='<%#Bind("LikId") %>' ></asp:Label>    
                            <asp:Label ID="lbl_NoConrolSev" runat="server" Text='<%#Bind("SevId") %>' ></asp:Label>    
                        </ItemTemplate>
                       <HeaderStyle HorizontalAlign="Left" Width="10%"></HeaderStyle>
                        </asp:TemplateField>
                         <asp:BoundField DataField="likelyhood" HeaderText="Likelyhood" >
                            <HeaderStyle Width="30%" />
                            </asp:BoundField>
                         <asp:BoundField DataField="severty" HeaderText="Severity" >
                            <HeaderStyle Width="30%" />
                            </asp:BoundField>
                         <asp:TemplateField>
                        <ItemTemplate>
                        <table id="tbl1"  runat="server" width="100%">
                        <tr>
                        <td  id="tdl1"  runat="server" style="font-weight: bold" align="center" width="50%">
                        <asp:Label ID="lbllevel1" runat="server" Text='<%#Bind("level") %>' ToolTip="Level"></asp:Label> </td>                                             
                       <td  id="tdl11"  runat="server" style="font-weight: bold" align="center" width="50%">
                        <asp:Label ID="lblRank1" ToolTip="Rank" runat="server" Text='<%#Bind("rank") %>'></asp:Label> </td>
                        </tr>
                        </table>                            
                        </ItemTemplate>
                           <
                        <HeaderStyle HorizontalAlign="Left" Width="20%"></HeaderStyle>  
                        </asp:TemplateField>                       
                         <asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center">
                         <ItemTemplate>
                         <asp:ImageButton ID="imgEdit" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/Images/Edit.gif" Text="Edit" />
                         <asp:Label ID="lbl_edit" runat="server"></asp:Label>
                       </ItemTemplate>   
                        <HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
                        <ItemStyle HorizontalAlign="Center" />
                      </asp:TemplateField>
                        </Columns>
                        </asp:GridView>
                        </td>
                        </tr>
                    </table>                
                </td>
            </tr></table>   </ContentTemplate> </asp:UpdatePanel>

推荐答案

Try adding this script. Mention the button name in getElementById function





Try adding this script. Mention the button name in getElementById function


<script type="text/javascript" language="javascript">
        window.onload = function () {
            document.getElementById("").focus();
        }
    </script>





OR



You can also set the TabIndex property of the controls.

For more information on TabIndex Property refer the following link:



http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tabindex(v=vs.110).aspx[^]



OR

You can also set the TabIndex property of the controls.
For more information on TabIndex Property refer the following link:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tabindex(v=vs.110).aspx[^]


这篇关于当我设置焦点在按钮上时,焦点自动设置在文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆