Avatar of tatton777
tatton777
Flag for United States of America

asked on 

Problem with defaultbutton on Enter Key

MY UNDERSTANDING ON HOW TO SET DEFAULTBUTTON
TO FIRE ON "ENTER KEY"
=======================================================
1. Section that has the defaultbutton defined in a panel
2. You have this javascript in the header (because of asp.net bug)
    function ResetDefaultFired()
    {
      __defaultFired = false;
    }

3. Set the OnClientClick="ResetDefaultFired" in all the buttons that are going to be used as default for the enter key.
====================================================



HERE'S WHAT IS HAPPENING
====================================================
I have for <div>s in my web page nestled inside an AJAX UpdatePanel. The div's are hidden and shown programmatically. Each of these divs will take turns appearing. No two divs will by Visible at the same time.

The first <div> shown on the initial render works great. However, when that <div> is hidden and the next <div> loads the default button described in the <panel> surrounding that <div> won't fire.

I hope that I'm clear. Code is below.

Thanks.



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 
 
    <title></title>
    <script language="JavaScript" src="https://seal.networksolutions.com/siteseal/javascript/siteseal.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
    function ResetDefaultFired()
    {
      __defaultFired = false;
    }
    </script>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
      .style1
      {
        color: #000000;
      }
      .style3
      {
        color: #990000;
        font-size: small;
      }
      .style4
      {
        font-size: large;
        font-weight: bold;
        color: #FF0000;
      }
    </style>
</head>
<body style="text-align: center; background-image: url('images/background.jpg'); background-color: #b3b8be; background-repeat: repeat-x">
    <form id="form1" runat="server" >
 
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
 
                                  <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmitEmployeeID">
                                  
                                  <div id="divEmployeeId" runat="server">
                                    <table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-family: Tahoma">
                                      <tr>
                                        <td style="vertical-align: middle; text-align: right; width: 270px">
                                          <asp:Label ID="lblEmployeeID" Text="Login ID" runat="server" 
                                            Font-Names="Tahoma" ForeColor="Black" style="font-size: medium" />
                                          &nbsp;&nbsp;
                                        </td>
                                        <td style="text-align: left">
                                          <asp:TextBox ID="txtEmployeeID" runat="server" Height="20px" Width="150px"></asp:TextBox>
                                          &nbsp;
                                          </td>
                                      </tr>
                                      <tr id="tr_password" runat="server">
                                        <td style="text-align: right">
                                          <asp:Label ID="lblEmployeePassword" runat="server" Font-Names="Tahoma" 
                                            ForeColor="Black" style="font-size: medium" Text="Password" />
                                          &nbsp;&nbsp;</td>
                                        <td style="text-align: left">
                                          <asp:TextBox ID="txtEmployeePassword" runat="server" Height="20px" 
                                            TextMode="Password" Width="150px"></asp:TextBox>
                                          &nbsp;
                                          </td>
                                      </tr>
                                      <tr>
                                        <td>
                                          &nbsp;</td>
                                        <td style="text-align: left">
                                          <asp:CheckBox ID="chkSubLogin" runat="server" Enabled="False" 
                                            style="color: #000000" Text="Check For Sub Login" />
                                        </td>
                                      </tr>
                                      <tr>
                                        <td>
                                          &nbsp;</td>
                                        <td style="text-align: left">
                                          <asp:Button ID="btnSubmitEmployeeID" runat="server" Text="Submit" 
                                            onclick="btnSubmitEmployeeID_Click1" CausesValidation="False" 
                                            style="color: #009900; font-weight: 700" OnClientClick="ResetDefaultFired" />
                                        </td>
                                      </tr>
<%--                                      <tr>
                                        <td>
                                          &nbsp;</td>
                                        <td style="text-align: left">
                                          &nbsp;&nbsp;</td>
                                      </tr>--%>
                                    </table>
                                  </div>                                 
                                  </asp:Panel>
 
<asp:Panel ID="Panel4" runat="server" DefaultButton="btnStopViewingAbsences">                                 
                                  <div id="divViewAbsencesButtons" runat="server">
                                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                      <tr>
                                        <td>&nbsp;</td>
                                      </tr>
                                      <tr>
                                        <td style="text-align: left">
                                           <asp:Button ID="btnStopViewingAbsences" runat="server" 
                                            Text="Stop Viewing Absences and Leave Balances" onclick="btnStopViewingAbsences_Click" 
                                             style="text-align: center; color: #009900; font-weight: 700;" 
                                             CausesValidation="False" OnClientClick="ResetDefaultFired" />
                                        </td>
                                      </tr>
                                    </table>
                                  </div>                                  
                                  </asp:Panel>
 
 
 
                                  <asp:Panel ID="Panel2" runat="server" DefaultButton="btnSubmitAbsenceType">                                  
                                  <div id="divExplainAbsences" runat="server" 
                                       style="background-image: url('images/metal_light.jpg'); border: solid 1px black">
                                          <table width="100%" border="0" cellpadding="0" cellspacing="4">
                                            <tr>
                                              <td colspan="3" style="text-align: left" class="style4">
                                                Please provide a reason for this absence.</td>
                                            </tr>
                                            <tr>
                                              <td colspan="3" style="text-align: left">
                                                <asp:Label ID="lblAbsenceHeader" runat="server" 
                                                  style="color: #000000; font-size: medium; font-weight: 700"></asp:Label>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td>
                                                &nbsp; &nbsp;</td>
                                              <td>&nbsp; &nbsp;
                                              </td>
                                              <td>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td class="style1" style="text-align: left">Absence Type</td>
                                              <td colspan="2" style="text-align: left">
                                                <asp:DropDownList ID="ddlAbsenceType" runat="server" >
                                                </asp:DropDownList>
                                                &nbsp;
                                                <asp:RequiredFieldValidator ID="rfDdlAbsenceType" runat="server" 
                                                  ControlToValidate="ddlAbsenceType" ErrorMessage="** Selection Required" 
                                                  Font-Bold="True" Font-Italic="True" Font-Names="Trebuchet MS" 
                                                  Font-Size="Medium" ForeColor="Black" InitialValue="0"></asp:RequiredFieldValidator>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td class="style1" style="text-align: left">Comment</td>
                                              <td colspan="2" style="text-align: left">
                                                <asp:TextBox ID="txtAbsenceComment" runat="server" Width="500px"></asp:TextBox>
                                              </td></tr>
                                            <tr>
                                              <td>&nbsp;&nbsp; &nbsp;</td>
                                              <td style="text-align: left">
                                                &nbsp;</td>
                                              <td style="text-align: right">
                                                &nbsp;</td>
                                            </tr>
                                            <tr>
                                              <td>
                                              </td>
                                              <td style="text-align: left">
                                                <asp:Button ID="btnSubmitAbsenceType" runat="server" 
                                                  onclick="btnSubmitAbsenceType_Click1" Text="Submit" 
                                                  style="color: #009933; font-weight: 700" OnClientClick="ResetDefaultFired" />
                                              </td>
                                              <td style="text-align: right">
                                                <asp:Button ID="btnCancelAbsenceType" runat="server" CausesValidation="False" 
                                                  onclick="btnCancelAbsenceType_Click1" Text="Enter Later" />
                                              </td>
                                            </tr>
                                          </table>
                                  </div> 
                                  </asp:Panel>
 
 
 
                                  <asp:Panel ID="Panel3" runat="server" DefaultButton="btnClockInOrOut">
                                  <div id="divButtons" runat="server">
                                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                      <tr>
                                        <td>&nbsp;</td>
                                        <td></td>
 
                                      </tr>
                                      <tr>
                                        <td style="text-align: left">
                                          <asp:Button ID="btnClockInOrOut" runat="server" 
                                            onclick="btnClockInOrOut_Click" CausesValidation="False" 
                                            style="color: #009900; font-weight: 700" OnClientClick="ResetDefaultFired"  />
                                          <asp:Button ID="btnViewAbsences" runat="server" Text="View Absences and Leave Balances" 
                                            onclick="btnViewAbsences_Click" CausesValidation="False" />
                                        </td>
                                        <td style="text-align:right">
                                          
                                          <asp:Button ID="btnExit" runat="server" Font-Bold="True" ForeColor="Blue" 
                                            Height="42px" onclick="btnExit_Click" Text="Exit" Width="110px" 
                                            CausesValidation="False" />&nbsp;&nbsp;&nbsp;&nbsp;
                                          
                                        </td>
 
                                      </tr>
                                    </table>
                                    &nbsp;&nbsp;
                                  </div>                                    
                                  </asp:Panel>
 
      </body>
    </html>

Open in new window

ASP.NET

Avatar of undefined
Last Comment
tatton777

8/22/2022 - Mon