2019独角兽企业重金招聘Python工程师标准>>>

今天在自学网上学习了一下页面之间控件的传值,通过Button中的PostBackUrl来实现页面的跳转,通过PreviousPage.FindControl(“”);来获取控件的id,以实现页面值的传递 .  但发现previousPage一直是null,为了避免代码原因,我随手写了个button来测试了一下:

c_set.aspx为传值页

<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/c_read.aspx"  />

c_read.aspx为接受页

c_read.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.PreviousPage != null)
        {
            Response.Write("previousPage不是空");
        }
        else
        {
            Response.Write("previousPage是空");
        }
    }

显示结果为previousPage为空

最后我在网上查了很久,才找到原因:When you use the default WebForm from visual Studio, the AutoRedirectMode is set to Permanent. This makes you request into a “GET” and since you are using Friendly URLs1, you can’t evaluate the PreviousPage.

The problem was the FriendlyUrls nuget package was removing the .aspx after my page names so my target page was not WebForm2.aspx but just WebForm2. This made the previous page null.

If you want a “POST” action then set the AutoRedirectMode = RedirectMode.Off (this will give you PreviousPage info but only from non-Friendly-Url pages [ex: www.you.com/mypage.aspx], however this will get you an error if you try to access the Friendly-Url page [ex: www.you.com/mypage] << no .aspx).

当你用建立网站的时候通过ASP.Net WEB窗体网站,那么在运行的时候浏览器会隐藏页面的后缀。

如果我们通过空网站建立WEB项目即:

那么previousPage就不会为空了。

c_read.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            Response.Write("previousPage可用");
        }

}

转载于:https://my.oschina.net/u/2494495/blog/521636

为什么PreviousPage为null相关推荐

  1. 错误日志——PreviousPage is null when attempting a cross-page postback using a button and the PostBack

    在创建的Web项目中尝试跨页面传值时,发现target page中PreviousPage总是空. 这意味着MY CROSS PAGE POSTING NOT WORKING,但是我确信所有的代码无误 ...

  2. pdf.js 实现阅读pdf文件

    pdf.js跨域读取文件pdf文件 1.pdf.js获取文件的方法 You can modify the defaultUrl app option in the web/app_options.js ...

  3. 中国最新行政地区表(mysql)

    在网上找了很多行政地区表,但是都没有最新的mysql版本,我自己整理了一份,供xdjm们参考: DROP TABLE IF EXISTS `region`; CREATE TABLE `region` ...

  4. 2019年全国省市区代码Oracle数据库脚本

    delete from DM_GB_B_ZHRMGHGXZQHDM; insert into DM_GB_B_ZHRMGHGXZQHDM (DM, MC, SM, ZT, ZHGXSJ) values ...

  5. 页面间传值的新思路--PreviousPage

    使用PreviousPage可以不需要,上一个页面为传值而去做相关的动作,以下三种形式不同的方法 PreviousPage:获取向当前页传输控件的页. 第一种方法: fromPage.aspx: // ...

  6. ASP.NET 网页中的跨页发送PreviousPage

    默认情况下,在 ASP.NET 网页中引起回发的按钮和其他控件将页提交回该页本身.这是 ASP.NET 网页在其正常的处理过程中所要经历的往返周期的一部分.在某些情况下,可能需要将一个页发送到其他页. ...

  7. 运用PreviousPage简化提交流程

    若是一个page1.aspx向page2.aspx提交的流程,则在page2.aspx的顶部添加如下声明: <%@ PreviousPageType VirtualPath="~/pa ...

  8. asp.net中的跨页发送(利用PreviousPage.FindControl()方法取值)

    <%@ Register src="Ascx/selectBox.ascx" tagname="selectBox" tagprefix="uc ...

  9. 当PreviousPage.FindControl遇到MasterPage,如何查找控件?

    有以下两个页面Default.aspx和Result.aspx,代码如下: <!-- Default.aspx --> <%@ Page Language="C#" ...

最新文章

  1. Dijkstra的算法
  2. uva-10152-乌龟排序
  3. Java和C语言的语句对比
  4. 【重要】有三AI视频直播间上线,100余小时AI课程等你来学
  5. PHP索引数组+unset使用不当导致的问题
  6. 博弈论——关于Nim游戏和SG函数的几个链接
  7. yum安装最新的 LNMP
  8. 站在巨人的肩膀,2020我在使用和涉及到的开源项目
  9. attr与prop的区别
  10. feign服务器响应数据量过大,SpringCloud之Feign 性能优化
  11. Windows下的SQL Server备份文件BAK在Linux环境下还原遇到的问题
  12. ctab法提取dna流程图_CTAB法提取植物基因组DNA过程图示
  13. vue echarts数据变化重新渲染_vue实例创建及数据挂载渲染
  14. OneNote 安装代码高亮插件 NoteHightlight的安装及使用基础教程
  15. 人肉搜索、人肉语言及人肉程序设计
  16. YYKit(Base模块)学习笔记
  17. MAC安装JDK详细教程
  18. 蜀门一直显示连接服务器,蜀门自身状态增加不召唤仙宠BUG玩法全解 利用的服务器自身...
  19. linux删除缓存文件swp,Vi下删除SWP文件
  20. java读取图片文字

热门文章

  1. oracle安装提示初始设置失败,安装oracle11g client 【INS-30131】执行安装程序验证所需的初始设置失败的解决方法...
  2. 前端开发中IE6,IE7,IE8的问题的汇总
  3. 已解决——“搜狗输入法如何进行候选页翻页”
  4. 墨者靶场 phpMyAdmin后台文件包含分析溯源 (CVE-2018-12613)
  5. 揭秘:技术风险如何保障支付宝的稳定性?
  6. 一张彩色图片,如何用Photoshop处理成一张轮廓图(就是变成刚用铅笔画出来时的那样)_......
  7. kmplayer 调左右声道
  8. linux下设定自动关机
  9. 粉丝破万啦!!感谢,感恩
  10. 串口使用及测量实验1