开发者

ASP.net redirect user on condition

开发者 https://www.devze.com 2023-01-20 15:15 出处:网络
Given my registration page: <asp:CompleteWizardStep ID=\"CompleteWizardStep1\" runat=\"server\">

Given my registration page:

            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                <ContentTemplate>

                    <span class="defHead">Thank You!</span><br /><br />
                    You are now registered on our system.<br /><br />

                </ContentTemplate>
            </asp:CompleteWizardStep>

   </WizardSteps&开发者_运维问答gt;

<CreateUserButtonStyle CssClass="searchBtn" Width="120" Height="26" />
<ContinueButtonStyle CssClass="searchBtn" Width="120" Height="26" />

I want to redirect the user if a condition is met, and they are at the above step. I've tried:

protected void Page_Load(object sender, EventArgs e)
        {
            if (CompleteWizardStep1.Visible)
            {
                Response.Redirect("viewBasket.aspx?action=news");
            }

But with no luck! Can't seem to find anything.


Found it out :)

On your create user wizard control add a reference to a function OnCreatedUser:

<asp:CreateUserWizard
        id="CreateUserWizard1"
        Runat="server"
        OnCreatedUser="CreatedUser"

Then define in your code the functionality you wish to run:

protected void CreatedUser(object sender, EventArgs e)
  {
      Response.Redirect("viewBasket.aspx?action=news");
  }

Note this will stop the user being logged into their account. To keep the user logged in:

    protected void CreatedUser(object sender, EventArgs e)
      {
                TextBox userNameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                MembershipUser user = Membership.GetUser(userNameTextBox.Text);
                FormsAuthentication.SetAuthCookie(userNameTextBox.Text, false);
                Response.Redirect("viewBasket.aspx?action=news");
      }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号