2013-04-29 110 views
1

用戶註冊之後我嘗試將客戶端重定向到默認頁面,並做到這一點似乎在提交按鈕結束要加入這一行的最簡單的方法:Response.Redirect(「Default.aspx」);不工作

Response.Redirect("Default.aspx"); 

,但它不工作,它保持在同一頁面中而不顯示任何錯誤。

我也試過用:

Server.Transfer("Default.aspx"); 

沒有任何的運氣。

繼承人完整代碼。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 

namespace Carnisoftix 
{ 
    public partial class Register : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
     } 

     protected void btnSubmit_Click(object sender, EventArgs e) 
     { 
      carniuser oUsr = new carniuser(); 
      oUsr.Email = txtEmail.Text; 
      oUsr.Name = txtName.Text; 
      oUsr.Pass = txtPassword.Text; 
      oUsr.Phone = txtPhone.Text; 
      oUsr.Usrname = txtUsername.Text; 
      oUsr.Address = txtAddress.Text; 
      oUsr.SpecialK = Convert.ToInt16(txtSpecial.Text); 
      oUsr.Auth = 1; 
      regUsr(oUsr); 

      Response.Redirect("Default.aspx"); 
     } 
     public static int regUsr(carniuser oUsr) 
     { 
      int oNum; 
      SqlConnection oConnection = new SqlConnection("Server=.\\SQLExpress;AttachDbFilename=L:\\Apps\\VS Projects\\Carnisoftix\\CarniDb.mdf;Database=CarniDb;Trusted_Connection=Yes;"); 
      string oSql = "ADDUSR"; 
      SqlCommand oCom = new SqlCommand(oSql, oConnection); 
      oCom.CommandType = CommandType.StoredProcedure; 
      oCom.Parameters.AddWithValue("@useremail", oUsr.Email); 
      oCom.Parameters.AddWithValue("@userpass", oUsr.Pass); 
      oCom.Parameters.AddWithValue("@name", oUsr.Name); 
      oCom.Parameters.AddWithValue("@phone", oUsr.Phone); 
      oCom.Parameters.AddWithValue("@address", oUsr.Address); 
      oCom.Parameters.AddWithValue("@username", oUsr.Usrname); 
      oCom.Parameters.AddWithValue("@authority", oUsr.Auth); 
      oCom.Parameters.AddWithValue("@special", oUsr.SpecialK); 
      SqlParameter oReturn = new SqlParameter("@out", SqlDbType.Int); 
      oReturn.Direction = ParameterDirection.ReturnValue; 
      oCom.Parameters.Add(oReturn); 
      oConnection.Open(); 
      oCom.ExecuteNonQuery(); 
      oNum = (int)oCom.Parameters["@out"].Value; 
      oConnection.Close(); 
      return oNum; 
     } 
    } 
    /*@useremail, 
    @username, 
    @userpass, 
    @name, 
    @phone, 
    @address, 
    @authority, 
    @special*/ 
    public class carniuser 
    { 
     private string email, usrname, pass, name, phone, address; 
     private int authority, specialK; 
     public carniuser() 
     { 
      email = ""; 
      usrname = ""; 
      pass = ""; 
      name = ""; 
      phone = ""; 
      address = ""; 
      authority = 1; 
      specialK = 1; 
     } 
     public string Email 
     { 
      get { return email; } 
      set { email = value; } 
     } 
     public string Pass 
     { 
      get { return pass; } 
      set { pass = value; } 
     } 
     public string Name 
     { 
      get { return name; } 
      set { name = value; } 
     } 
     public string Phone 
     { 
      get { return phone; } 
      set { phone = value; } 
     } 
     public string Address 
     { 
      get { return address; } 
      set { address = value; } 
     } 
     public string Usrname 
     { 
      get { return usrname; } 
      set { usrname = value; } 
     } 
     public int Auth 
     { 
      get { return authority; } 
      set { authority = value; } 
     } 
     public int SpecialK 
     { 
      get { return specialK; } 
      set { specialK = value; } 
     } 

     public carniuser(string email, string usrname, string pass, string name, string phone, string address, int authority, int specialK) 
     { 
      //string _email = email; 
      Email = email; 
      Usrname = usrname; 
      Pass = pass; 
      Name = name; 
      Phone = phone; 
      Address = address; 
      Auth = authority; 
      SpecialK = specialK; 
     } 
    } 
} 
+1

你確定你實際提交的數據?你有沒有放置一個斷點,並看到事件處理程序被解僱? – Oded 2013-04-29 11:23:22

+2

試試這個 - >'Response.Redirect(「〜/ Default.aspx」,true);' – Elyor 2013-04-29 11:23:47

+1

你確定路徑正確嗎? Default.aspx必須與當前頁面位於同一文件夾中。 – guilhermecgs 2013-04-29 11:24:01

回答

2

我必須知道註冊頁面在哪裏? Default.aspx是在不同的文件夾?

但試試這個

Response.Redirect("../Default.aspx"); 

Response.Redirect("~/Default.aspx"); 

我希望這有助於。

+1

試過兩個,他們在同一個目錄。我開始想我應該重新啓動VS. – octohedron 2013-04-29 11:56:28

+0

你試圖跟蹤代碼?也許有錯誤? – 2013-04-29 11:57:43

+0

右鍵單擊解決方案資源管理器中的項目文件夾,然後單擊清理 – Rahul 2013-04-29 11:57:47

-1

據我所知,提交按鈕將導致一個回發,它將執行您的代碼,然後重新加載頁面。嘗試將此添加到您的Page_Load中:

Response.Redirect("Default.aspx"); 
+1

仍然不能正常工作 – octohedron 2013-04-29 11:31:33

+0

重定向已經在點擊按鈕內(僅在回發站上被調用) – Aristos 2013-04-29 11:31:41

+0

IsPostBack在這種情況下沒有任何作用.... – Rahul 2013-04-29 11:33:55

相關問題