如果Form提交的本页,页面就无法跳转了吗?

coverallwangp 2010-05-20 11:21:21
我用了:仿163网盘上传文件 做了一个图片上传页面


<form id="uploadForm" runat="server" defaultbutton="btnlogin">
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="232" valign="top"><!--#include file="leftbar.aspx"--></td><%--左侧的用户登录窗口--%>
<td>右侧的上传图片的区域</td>
</form>

首先:图片已可以上传成功。设置uploadForm的action为"File.ashx",完成图片上传。

但是我左侧的登录区域却出现了问题。登录后页面没有反映,我测试后发现,代码已经执行,只是在最后的页面跳转语句没有执行。
登录成功后跳转到首页:
//Response.Redirect("Default.aspx",false);
Server.Transfer("Default.aspx");

是不是应为Form提交的原因造成的?该如何解决呢?
...全文
1056 50 打赏 收藏 转发到动态 举报
写回复
用AI写文章
50 条回复
切换为时间正序
请发表友善的回复…
发表回复
coverallwangp 2010-06-02
  • 打赏
  • 举报
回复
解决了,阿飞真是牛人,呵呵
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 47 楼 koko379314367 的回复:]
<input type=button value="测试下" />
[/Quote]

111

coverallwangp 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 38 楼 sandy945 的回复:]
C# code
Response.Write("<script>window.parent.location.href='Default.aspx';</script>");
[/Quote]
=>
C# code
Response.Write("<script>window.parent.location.href='Default.aspx';<"+"/"+"script>");
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
<input type=button value="测试下" />
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quoddte=引用 45 楼 koko379314367 的回复:]
引用 37 楼 coverallwangp 的回复:
还是没有成功
但我肯定程序已经执行了,因为我手动刷新一下页面,马上就会显示已登录
登录按钮的点击事件:

protected void btnlogin_Click(object sender, EventArgs e)
{
if (IsValid)
{
if (txtacc.Text.Trim() == "" || txtp……
[/Quote]
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 37 楼 coverallwangp 的回复:]
还是没有成功
但我肯定程序已经执行了,因为我手动刷新一下页面,马上就会显示已登录
登录按钮的点击事件:

protected void btnlogin_Click(object sender, EventArgs e)
{
if (IsValid)
{
if (txtacc.Text.Trim() == "" || txtpsd.Text.Trim() == "")
{
lbltip.Text = "用户名或密码为空!";
}
else
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ershouConnectionString"].ToString());
if (conn.State != System.Data.ConnectionState.Open)
{
conn.Open();
}
//string sql = "select n_id,n_title,convert(varchar(10),n_time,120) as n_time from t_notice order by n_time desc";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select * from t_user where u_name='" + txtacc.Text.ToString() + "' and u_password='" + txtpsd.Text.ToString() + "' and u_state='正常'", conn);
//SqlDataReader dr = app.ExecuteReader("select * from t_user where u_name='" + txtacc.Text.ToString() + "' and u_password='" + txtpsd.Text.ToString()+"' and u_state='正常'");
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
cmd.Dispose();
if (!dr.Read())
{
lbltip.Text = "用户名或密码有误!";
dr.Dispose();
conn.Dispose();
}
else
{
Session["account"] = txtacc.Text.ToString();
Session["password"] = txtpsd.Text.ToString();
dr.Dispose();
conn.Dispose();
//Response.Redirect("Default.aspx",false);
//Server.Transfer("Default.aspx");
Response.Write("<script>window.parent.location.href='Default.aspx';<//script>");
Response.End();
}
}
}
}

[/Quote]


111111111111111111
阿非 2010-06-02
  • 打赏
  • 举报
回复
额~ 因为你是写在.aspx 文件中的,所以会报这个错。

如下:

Response.Write("<script>window.parent.location.href='Default.aspx';"+"</scr" + "ipt>");
Response.End();
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 warraner 的回复:]
前台页面主要代码:

HTML code

<form id="uploadForm" runat="server" defaultbutton="btnlogin">
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <!--#includ……
[/Quote]



fghfgh
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 tangwei5233 的回复:]
登陆之后也不执行跳转代码吗?? 换个别的跳转方式的代码试试, 18楼没看见form ,没form有的时候会报错才对啊,c#技术群:108806769
[/Quote]




ddddddddddddddddd
看那一米阳光 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 40 楼 coverallwangp 的回复:]
C# code

编译器错误信息: CS1010: 常量中有换行符

源错误:



行 51: //Response.Redirect("Default.aspx",false);
行 52: //Server.Transfer("Default.aspx");
行 53: ……
[/Quote]



sdfsdfsdf
coverallwangp 2010-06-02
  • 打赏
  • 举报
回复

编译器错误信息: CS1010: 常量中有换行符

源错误:



行 51: //Response.Redirect("Default.aspx",false);
行 52: //Server.Transfer("Default.aspx");
行 53: Response.Write("<script>window.parent.location.href='Default.aspx';</script>");
行 54: Response.End();
行 55: }


源文件: e:\Development\TotalPro\ershouback\leftbar.aspx 行: 53
coverallwangp 2010-06-02
  • 打赏
  • 举报
回复
提示有错误,</script>的斜杠会不会被理解成了转义符???
[Quote=引用 38 楼 sandy945 的回复:]
[Quote=引用 37 楼 coverallwangp 的回复:]

C# code

Response.Write("<script>window.parent.location.href='Default.aspx';<//script>");
Response.End();



[/Quote]

=>


C# code

Response.Write(……
[/Quote]
阿非 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 37 楼 coverallwangp 的回复:]

Response.Write("<script>window.parent.location.href='Default.aspx';<//script>");
Response.End();


[/Quote]

=>


Response.Write("<script>window.parent.location.href='Default.aspx';</script>");
coverallwangp 2010-06-01
  • 打赏
  • 举报
回复
还是没有成功
但我肯定程序已经执行了,因为我手动刷新一下页面,马上就会显示已登录
登录按钮的点击事件:

protected void btnlogin_Click(object sender, EventArgs e)
{
if (IsValid)
{
if (txtacc.Text.Trim() == "" || txtpsd.Text.Trim() == "")
{
lbltip.Text = "用户名或密码为空!";
}
else
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["ershouConnectionString"].ToString());
if (conn.State != System.Data.ConnectionState.Open)
{
conn.Open();
}
//string sql = "select n_id,n_title,convert(varchar(10),n_time,120) as n_time from t_notice order by n_time desc";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select * from t_user where u_name='" + txtacc.Text.ToString() + "' and u_password='" + txtpsd.Text.ToString() + "' and u_state='正常'", conn);
//SqlDataReader dr = app.ExecuteReader("select * from t_user where u_name='" + txtacc.Text.ToString() + "' and u_password='" + txtpsd.Text.ToString()+"' and u_state='正常'");
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
cmd.Dispose();
if (!dr.Read())
{
lbltip.Text = "用户名或密码有误!";
dr.Dispose();
conn.Dispose();
}
else
{
Session["account"] = txtacc.Text.ToString();
Session["password"] = txtpsd.Text.ToString();
dr.Dispose();
conn.Dispose();
//Response.Redirect("Default.aspx",false);
//Server.Transfer("Default.aspx");
Response.Write("<script>window.parent.location.href='Default.aspx';<//script>");
Response.End();
}
}
}
}

[Quote=引用 33 楼 sandy945 的回复:]
不是没跳转,而是因为 你是用 iframe 代替 当前页的 form 进行了提交
相对的 跳转 也是 iframe 进行了跳转。
而你想让当前页跳转,可以写
C# code
Response.Write("<script>window.parent.location.href='default.aspx';</script>");
Response.End();
[/Quote]
coverallwangp 2010-06-01
  • 打赏
  • 举报
回复
我试试

[Quote=引用 33 楼 sandy945 的回复:]
不是没跳转,而是因为 你是用 iframe 代替 当前页的 form 进行了提交

相对的 跳转 也是 iframe 进行了跳转。

而你想让当前页跳转,可以写


C# code
Response.Write("<script>window.parent.location.href='default.aspx';</script>");
Response.End();
[/Quote]
army369168520 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 33 楼 sandy945 的回复:]
不是没跳转,而是因为 你是用 iframe 代替 当前页的 form 进行了提交

相对的 跳转 也是 iframe 进行了跳转。

而你想让当前页跳转,可以写


C# code
Response.Write("<script>window.parent.location.href='default.aspx';</script>");
Response.End();
[/Quote]
分析的有道理! UP!!
army369168520 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 warraner 的回复:]
不知道什么原因,我的VS经常无法调试,设置断点后没有反应,直接运行了
[/Quote]
你在前台设置的断点,还是后台
if(前台设置的断点)
{
return 不会执行;
}
else
{
if(后台设置的断点语句错误)
{
return 不会执行;

}
else
{
return 执行成功;//如果你还没成功调试,可能你的RP差了。杯具!

}
}
阿非 2010-06-01
  • 打赏
  • 举报
回复
不是没跳转,而是因为 你是用 iframe 代替 当前页的 form 进行了提交

相对的 跳转 也是 iframe 进行了跳转。

而你想让当前页跳转,可以写

Response.Write("<script>window.parent.location.href='default.aspx';</script>");
Response.End();
coverallwangp 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 sandy945 的回复:]
你说的不能跳转是 在应用了 iframe 提交的情况下么
[/Quote]

阿非 2010-06-01
  • 打赏
  • 举报
回复
你说的不能跳转是 在应用了 iframe 提交的情况下么
加载更多回复(30)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧