ASP.net没有回发到正确的页面 [英] ASP.net not posting back to correct page

查看:54
本文介绍了ASP.net没有回发到正确的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的应用程序类型有点不合常规.

我有一个名为AddNewBlog.aspx的aspx页面.该页面从数据库查询生成XML数据,并且包含文件AddNewBlogXSL.aspx,它是一个xsl样式表.这样做的结果是,AddNewBlog XML数据由客户端的AddNewBlogXSL转换为XHTML.

因此,尽管请求的页面是AddNewBlog.aspx,但是布局,控件和表单位于AddNewBlogXSL.aspx上,因为它包含所有布局和格式.
在AddNewBlogXSL.aspx上,我执行一个asp:button,它试图将其回发到AddNewBlogXSL.aspx,这是可以理解的.

问题在于该页面是xslt样式表,而不是网页..我需要将其发布回AddNewBlog.aspx,因为这是包括AddNewBlogXSL.aspx的正确页面

我似乎唯一能做的就是允许默认行为,即提交给AddNewBlogXSL.aspx,处理该页面,然后将其重定向到正确的页面AddNewBlog.aspx,但是这样就很难处理错误了消息之类的原因,因为我仅从AddNewBlogXSL.aspx重定向到AddNewBlog.aspx之后就无法控制它了.

有什么想法吗?

解决方案

您正在寻找

为了解决您的评论,在这种情况下,IsPostBack将为 not 为true,因为它不是回发,而只是发布到另一个页面.您必须通过我列出的MSDN文章中概述的Page.PreviousPage属性访问这些值.

在跨页面回发期间,源页面控件的内容被发布到目标页面,并且浏览器执行HTTP POST操作(而不是GET操作).但是,在目标页面中,跨页面发布后,IsPostBack属性立即为false.尽管此行为是POST的行为,但交叉发布不是将其回发到目标页面.因此,IsPostBack设置为false,目标页面可以通过其首次代码.

还根据MSDN,您将检查PreviousPage.IsCrossPagePostBack属性而不是Page.IsPostBackProperty

  if(PreviousPage.IsCrossPagePostBack == true){//从PreviousPage获取值文本=(((TextBox)PreviousPage.FindControl("TextBox1")).Text;} 

跨页发布详细信息

我继续写了一些测试工具(又名,我从MSDN页面上摘下了示例::-0)进行验证,结果如下:跨页发布:

这不是理想的情况,而且很费力地访问列出的值,但是对于您设计的模型,这是我能想到的最好的方法.

So I have a slightly unorthodox application type.

I have an aspx page called AddNewBlog.aspx. This page generates XML data from database queries and it include the file AddNewBlogXSL.aspx which is an xsl style sheet. The effect is that the AddNewBlog XML data is transformed by AddNewBlogXSL on the client side into XHTML.

So although the requested page is AddNewBlog.aspx, the layouts and controls and forms are on AddNewBlogXSL.aspx since it contains all the layout and formatting.
When on AddNewBlogXSL.aspx I do an asp:button it tries to post back to AddNewBlogXSL.aspx as is understandable.

The problem is that page is an xslt stylesheet not a webpage.. I need it to post back to AddNewBlog.aspx as this is the proper page which includes AddNewBlogXSL.aspx

The only thing I seem to be able to do is allow the default behaviour which is to submit to AddNewBlogXSL.aspx, process the page, and redirect them to the proper page AddNewBlog.aspx but then it makes it hard to handle error messages and such since I have no control over AddNewBlog.aspx after I have simply redirected to it from AddNewBlogXSL.aspx

Any ideas at all?

解决方案

You are looking for PostBackUrl property.

<asp:button id="Button2"
  text="Post value to another page" 
  postbackurl="~/Path/To/AddNewBlog.aspx" 
  runat="Server">
</asp:button>

EDIT:

To address your comment, IsPostBack will not be true in this scenario because it isn't a postback, it's just a post to another page. You have to access the values via the Page.PreviousPage property as outlined in the MSDN article I listed.

During a cross-page postback, the contents of the source page's controls are posted to the target page, and the browser executes an HTTP POST operation (not a GET operation). However, in the target page, the IsPostBack property is false immediately after a cross-page post. Although the behavior is that of a POST, the cross-posting is not a postback to the target page. Therefore, IsPostBack is set to false and the target page can go through its first-time code.

Also per MSDN, you would check the PreviousPage.IsCrossPagePostBack property instead of the Page.IsPostBackProperty

if(PreviousPage.IsCrossPagePostBack == true)
{
     //Get values from PreviousPage
    text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
}

Cross Page Posting Details

I went ahead and wrote a little test harness (aka, I took the example off the MSDN page, :-0 )to verify and results are as follows when cross page posting:

It's not an ideal situation and it kludgey to access your values as listed, but for the model you have designed, it's the best I can think of.

这篇关于ASP.net没有回发到正确的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆