SharePoint回发问题

时间:2012-04-03 12:06:47

标签: sharepoint postback

我使用sendMail函数创建了Web部件表单。

        protected void btnSubmitForm_Click(object sender, EventArgs e)
    {
          SendEmail();
          ClearFields();
    }

但是当页面加载邮件发送时(使用最后的字段数据),不仅通过单击按钮...有人知道解决方案吗? 非常感谢!

我创建了CustomControl并将它们添加到webpart。 Web部分我已添加到页面布局使用。 Code Behind和html代码在CustomControl中:

protected void Page_Load(object sender,EventArgs e)         {

        if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
        {

            foreach (BaseValidator val in Page.GetValidators("Form"))
            {
                val.Enabled = false;
            }


            btnSubmitForm.Enabled = false;

        }
    }

    protected void btnSubmitForm_Click(object sender, EventArgs e)
    {
        try
        {
            SendEmail();
        }
        catch (Exception ex)
        {
            ExceptionHelper.LogException(ex);
        }

        ClearFields();


    }

2 个答案:

答案 0 :(得分:0)

您应该考虑IsPostback。另外,see this answer

答案 1 :(得分:0)

我找到了解决方案。我添加了下一个代码:

if (!String.IsNullOrEmpty(txtName.Text))
            {
                try
                {
                    SendEmail();
                }
                catch (Exception ex)
                {
                    ExceptionHelper.LogException(ex);
                }

                ClearFields();
                Response.Redirect("#");


            } 

它对我有用,因为在重定向到同一页面后,每次刷新后都不会发送邮件,只需提交表单即可。也许这不是很好的解决方案,但它确实有效!

P.S你也可以使用这个重定向Response.Redirect(Request.Url.ToString())代替以前的