0
votes

I am new to .Net and I want to create a button to redirect from a page to another. here is my c# code .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, System.EventArgs e)
    {

    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        InitializeComponent();
        base.OnInit(e);
    }

    private void InitializeComponent()
    {

    }
    #endregion

    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Response.Redirect("Default2.aspx", true);
    }
}

and this is my .net code

< % @ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

        <button id="Button 2"  onclick="Button2_Click"  type=" button " runat="server ">   NEW Account</  button>

My aspx file name is Default and my aspx.cs file name is also Default. THANKS!

1

1 Answers

0
votes

Use the asp button in your default.aspx page. <asp:Button ID="Button2" runat="server" Text="New Account" OnClick="Button2_Click" />.