0

I am trying to use PostBackUrl in my default.aspx page to postback to my memberlogin.aspx page. When I try to cast the PreviousPage object to a _Default page object, in the code behind for memberlogin.aspx I get this error:

CS0030: Cannot convert type '_Default' to 'ASP.default_aspx'

Why won't it let me cast it? Without casting it I can't access the default pages properties (I have tried using interfaces too, same problem).

1 Answer 1

2

To access public members of your previous page, define your previous page with PreviousPageType directive :

<%@ PreviousPageType VirtualPath="~/Default.aspx"%>
Sign up to request clarification or add additional context in comments.

2 Comments

I also tried another way, by removing the PreviousPageType directive and casting the PreviousPage as _Default page in the memberlogin.aspx code behind, however the PreviousPage is populated, but when casted, the casted page becomes null! What is going on?
I found this was because the cross postback pages I am using, both use a Master page, so it worked doing this and accessing it this way: TextBox t = Page.PreviousPage.Master.FindControl("Main").FindControl("textBox1") as TextBox;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.