2017-10-08 78 views
0

以下代码段(按钮触发)可用于调试模式,但除调试模式外,此按钮不起作用。在带有断点的调试模式下它工作正常。当我在没有调试模式的情况下尝试启动时,按钮不起作用。Asp.net按钮仅在调试模式下触发,但不在其他模式下

的.aspx代码

<div class="panel panel-danger"> 
     <div class="panel-heading"> 
      Site Attendance 
     </div> 
     <div class="panel-body"> 
      <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
       <ContentTemplate> 
        <div class="container-fluid"> 
         <table> 
          <tr> 
           <td> 
            <asp:DropDownList ID="ddlProjects" runat="server" AutoPostBack="true"></asp:DropDownList> 
           </td> 
          </tr>       
          <tr> 
           <td> 
            <asp:Button ID="btnPunch" Enabled="true" runat="server" Text="Punch" OnClick="btnPunch_Click" CausesValidation="false" /> 
           </td> 
          </tr> 
         </table> 
        </div> 
       </ContentTemplate> 
      </asp:UpdatePanel> 
     </div> 
    </div> 

而且代码的.cs

protected void btnPunch_Click(object sender, EventArgs e) 
    { 
     GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(); 
     watcher.TryStart(false, TimeSpan.FromMilliseconds(1000)); 
     GeoCoordinate coord = watcher.Position.Location; 
     double la = coord.Latitude; 
     double lo = coord.Longitude; 

     string userName = null; 
     if (User.Identity.IsAuthenticated) 
      userName = User.Identity.Name; 

     List<AppUsers> list = UsersManager.GetByUserName(userName); 
     int employeeId = list[0].UserId; 

     SitePunch obj = new SitePunch(); 

     try 
     { 
      if (la != 0 && lo != 0) 
      { 
       obj.Employee_ID = Convert.ToInt32(employeeId); 
       obj.Latitude = Convert.ToDecimal(la); 
       obj.Longitude = Convert.ToDecimal(lo); 
       obj.Project_Name = Convert.ToString(ddlProjects.SelectedValue); 

       int sitePunchInsert = SitePunchManager.Insert(obj); 

       if (sitePunchInsert != 0) 
       { 
        ShowMessage("Your Punch is Successful"); 
       } 
      } 
      else 
      { 
       ShowMessage("Please Select a Project First"); 
      } 

     } 

     catch (Exception ex) 
     { } 
    } 

如何来解决这个问题。提前致谢。

回答

1

尝试的UpdatePanel设置UpdateMode属性为“Conditional”,然后添加正确的触发

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="btnPunch" EventName="Click"> 
      </asp:AsyncPostBackTrigger> 
     </Triggers> 
    </asp:UpdatePanel> 

如果aboive设置不工作,那么你可以尝试设置ChildrenAsTriggers为true,并添加事件名称=“点击” asp:AsyncPostBackTrigger

+0

我试过了你的建议,但仍然无效。 – Khaza

+0

你试过两种解决方案? –

+0

是的,我尝试了两个。基本上我不明白是什么问题。我尝试了包括你在内的所有可能的解决方案,但它不起作用 – Khaza

相关问题