2017-10-08 84 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

相關問題