Asp.net按钮仅在调试模式下启动,但在其他模式下不启动

时间:2017-10-08 08:55:24

标签: c# 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 个答案:

答案 0 :(得分:1)

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

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

如果abotive设置不起作用,那么您可以尝试将ChildrenAsTriggers设置为true,并在asp:AsyncPostBackTrigger

中添加EventName =“Click”