使用c#代码在sharepoint 2010 webpart(沙盒解决方案)中进行页面重定向是可能的吗?

时间:2012-07-05 10:32:00

标签: redirect sharepoint-2010 sandbox office365

我正在使用沙盒解决方案(sharepoint 2010项目在Office 365上,因此使用沙盒解决方案)并希望在按钮单击事件上从一个页面转到另一个页面。这是通过javascript实现的,但是没有执行click事件中的操作。

例如,我将页面加载时的javascript分配给所需的事件,然后事件执行重定向而不进入事件内的代码。

用于重定向的javascript是:

string redirectURL = "http://ksreejit:32512/sites/SplTeam/Pages/QuizMasterDashboard.aspx";
btnCancel.Attributes.Add("OnClick", "javascript:{window.location='" + redirectURL + "';return false;}");

事件代码是:

protected void btnSubmit_Click(object sender, EventArgs e)
        {

            if (ViewState["QuestionID"].ToString() != string.Empty)
            {
                SaveDetails(ViewState["QuestionID"].ToString());
                foreach (Control contrl in this.Controls)
                {
                    contrl.Visible = false;
                }

            } 
            else
            {
                SaveDetails();
                foreach (Control contrl in this.Controls)
                {
                    contrl.Visible = false;
                }

            }
            Label lblMessage = new Label();
            lblMessage.Visible = true;
            lblMessage.Text = "The Question is successfully saved and sent to reviewer for reviewing. Thanks for uploading.";

   }

正如您所看到的,重定向成功地适用于btnCancel。我没有为btnSubmit指定它,因为它只会重定向,不会转到上面指定的代码.Tried microsoft帮助他们也是无能为力。答案将不胜感激。项目要求已被修改。很久没有答案请检查更多。提前谢谢。

2 个答案:

答案 0 :(得分:5)

点击按钮

添加此代码
string redirectURL = "http://ksreejit:32512/sites/SplTeam/Pages/QuizMasterDashboard.aspx";
this.Controls.Add(new LiteralControl("<script>window.location.href='" + redirectURL + "';</script>"));

答案 1 :(得分:1)

对于btnSubmit按钮,请不要像为btnCancel那样添加属性。 然后只需在事件方法中添加Response.Redirect(...);

... lblMessage.Text = "The Question is successfully saved and sent to reviewer for reviewing. Thanks for uploading.";

Response.Redirect("http://ksreejit:32512/sites/SplTeam/Pages/QuizMasterDashboard.aspx");