button_Click事件永远不会发生

时间:2019-02-14 04:11:59

标签: master-pages pageload buttonclick

我有一个利用母版页的Web应用程序。由于某种原因,当我添加一个buttonclick事件时,该方法永远不会被点击。该页面经历正常的page_load事件。如何触发按钮点击事件?以前,这工作得很好,现在这在我的整个应用程序中都发生了,其中!page.IsPostBack始终从button_Click

评估为false

我尝试添加脚本处理程序,但这似乎无济于事

在用户界面页面中:

<asp:Button ID="Button1" CssClass="btn btn-primary" 
OnClick="putAccoutDetail" runat="server" Text="Save Changes" />

在背后的代码中

protected void Page_Load(object sender, EventArgs e)
{
  if (Session["Authenticated"] == null || 
   Session["Authenticated"].ToString() != "true")
        {
            Response.Redirect("~/Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            if (Session["UserID"] != null)
            {
                UserID = Convert.ToInt32(Session["UserID"]);
                getUserData(UserID);
            }
        }

    }

 public void putAccoutDetail(object sender, EventArgs e)
    {
        string statusMsg = string.Empty;
        var userInfo = db.UserMasts.FirstOrDefault(s => s.ID == UserID);
        if (userInfo != null)
        {
            userInfo.UserName = txtUserName.Text;
            userInfo.MilEmail = txtEmail.Text; 

            string base64 = Request.Form["imgCropped"];
            if (base64.Length > 0)
            {
                byte[] bytes = Convert.FromBase64String(base64.Split(',')[1]);
                String fileName = Guid.NewGuid().ToString() + ".png";
                userInfo.PhotoPath = fileName;
                ImagePhoto.ImageUrl = "/Images/Users/" + userInfo.PhotoPath;
                using (FileStream stream = new FileStream(Server.MapPath("~/Images/Users/" + fileName), FileMode.Create))
                {
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Flush();
                }
            }
        }

        try
        {
            dHelper.LogAction("Update User Detail : " + userInfo.UserName);
            db.SubmitChanges();

            statusMsg = "Successfully Updated";
            lblstatusMsg.Text = statusMsg;
            lblstatusMsg.Visible = true;

        }
        catch(Exception ex)
        {
            statusMsg = "Update Failed";
            lblstatusMsg.Text = statusMsg;
            lblstatusMsg.Visible = true;
        }            

    }

1 个答案:

答案 0 :(得分:0)

问题是该表单在某些字段上有未处理的ASP验证程序。我向其中添加了一个验证组,然后在button_Click中对其进行了处理,一切正常