More in this section

Forums / Developing with Sitefinity / Cross page Postback

Cross page Postback

13 posts, 0 answered
  1. nathan leverington
    nathan leverington avatar
    6 posts
    Registered:
    13 Dec 2009
    22 Feb 2010
    Link to this post
    Hi,

    I am having trouble getting cross page postback to work.  I have read the MSDN documentation (http://msdn.microsoft.com/en-us/library/ms178139%28VS.80%29.aspx).

    I get an error whenever trying to use Page.PreviousPage inside the destination control.

    Here is the code for the source control (the control posting the data):

    <%@ Control Language="VB" ClassName="sourceForm" %>

    <script runat="server">

        Protected Sub button1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click       

            label1.Text = "hello" '& " " & textbox1.Text

        End Sub
       
    </script>

        Enter your name: <br />

        <asp:TextBox ID= "textbox1" runat="server"></asp:TextBox>

       <asp:Button ID= "button2" runat="server" Text="Submit Page to the Page2.aspx" PostBackUrl="~/Destination.aspx" />

       <asp:Label ID="label1" runat="server" ></asp:Label>



    The destination control's code:

    <%@ Control Language="VB" ClassName="Destination" %>
     
    <script runat="server">
     
        Protected Sub page_load(ByVal sender As Object, ByVal e As System.EventArgs)
     
            Dim GetTextBox1 As TextBox
       
            GetTextBox1 = CType(Page.PreviousPage.FindControl("textbox1"), TextBox)
     
            label1.Text = "hello " & GetTextBox1.Text
     
        End Sub
         
    </script>
     
     
    <asp:Label ID ="label1" runat="server"></asp:Label>


    This is the error I get:

    Server Error in '/prototype1' Application.
    --------------------------------------------------------------------------------
     
    The file '/prototype1/Source.aspx' does not exist.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.Web.HttpException: The file '/prototype1/Source.aspx' does not exist.
     
    Source Error:
     
     
    Line 11:   
    Line 12:
    Line 13:         GetTextBox1 = CType(Page.PreviousPage.FindControl("textbox1"), TextBox)
     
     
    Source File: E:\Program Files\telerik\Sitefinity3.7 Community\WebSites\prototype1\UserControls\Destination.ascx    Line: 13

    Please help!

    thanks



  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Feb 2010
    Link to this post
    i've never done anything like this before, but try using your debugger to check the PreviousPage property at line 13 and see what is in there. It shouldn't be null if you're cross posting (PreviousPage.IsCrossPagePostBack should also be true)

    another option you might consider is using the Request.Form to retrieve values from a posted form, but this depends on your application...

    sorry I don't have more specific info but I hope this was helpful!
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hi SelArom,

    You can use Server.Transfer or Request.UrlReferrer.ToString() to get the previous page. Then you can cast the node to ICmsPage and use the manage to get all controls and set the label text. Another option is passing the values by using Session, QueryStrings or cookie. Generally Sitefinity pages are internally created and Page object will return cmsentrypoint page, so you should better wrork with ICmsPage objects or using one of the another apporaches described above.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. nathan leverington
    nathan leverington avatar
    6 posts
    Registered:
    13 Dec 2009
    23 Feb 2010
    Link to this post
    Thanks for your response.  Can you please tell me how to get the previous page as an ICmsPage object?  I can't figure out how to do it.

    I know I can get the current page with:

    ' get the current node of sitemap
    Dim currentNode As Telerik.Cms.Web.CmsSiteMapNode = SiteMap.CurrentNode
     
    ' get the CmsPage represented by the current node
    Dim currentPage As Telerik.Cms.ICmsPage = currentNode.GetCmsPage()

    But how can I get the previous page? Remember that ultimately I just want to be able to get the value of form fields in the previous page (In PHP programming I would describe my problem as simply as wanting to get the POST variables)!!!!

    Also, Server.Transfer("~/MyPage.aspx") does not work for me, I get "Page not Found" error.  What's with that?

    thanks for your help

    -- Kee Fai
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Feb 2010
    Link to this post
    Hello nathan leverington,

    You can use Request.UrlReferrer.ToString() to get the url then get the SiteMap node using SiteMap.Provider.FindSiteMapNode and cast it to ICmsPage.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. nathan leverington
    nathan leverington avatar
    6 posts
    Registered:
    13 Dec 2009
    23 Feb 2010
    Link to this post
    I tried that using the method you described, but I get an error casting!

    Dim node As ICmsPage = SiteMap.Provider.FindSiteMapNode(Request.UrlReferrer.ToString())

    But I get the error:

    Unable to cast object of type 'Telerik.Cms.Web.CmsSiteMapNode' to type 'Telerik.Cms.ICmsPage'


    Please help!
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Feb 2010
    Link to this post
    Hello nathan leverington,

    Try using this

    Telerik.Cms.Web.CmsSiteMapNode somePage= (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.Provider.FindSiteMapNode(url);
    ICmsPage prvPage = (ICmsPage)cmsManager.GetPage(somePage.CmsPage.ID);


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    23 Feb 2010
    Link to this post
    the node itself can't be cast to a page, you have to retrieve the page the node points to:

    try this:

    var node = SiteMap.Provider.FindSiteMapNode(Request.UrlReferrer.ToString()) as Telerik.Cms.Web.CmsSiteMapNode;
    var page = node.GetCmsPage() as Telerik.Cms.IcmsPage

    however, won't this only create a "new" instance of that page? I might be missing something but how is this new instance going to contain the cross-posted items?

    just curious how this all works
  9. nathan leverington
    nathan leverington avatar
    6 posts
    Registered:
    13 Dec 2009
    23 Feb 2010
    Link to this post
    Ok so now I have the ICmsPage object, can you please show me how to get all the controls on the page?

    thanks
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Feb 2010
    Link to this post
    Hi nathan leverington,

    You can get the controls from the Controls collection.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  11. nathan leverington
    nathan leverington avatar
    6 posts
    Registered:
    13 Dec 2009
    24 Feb 2010
    Link to this post
    Ok I managed to get the control of the previous state using the code below:

    ' Get the previous page
        Dim somePage As Telerik.Cms.Web.CmsSiteMapNode = SiteMap.Provider.FindSiteMapNode("~/Source.aspx")
        Dim prvPage As ICmsPage = cmsManager.GetPage(somePage.GetCmsPage().ID)
     
    ' Get the controls
    Dim myList As IList = prvPage.Controls
     
    ' loop through the controls and get the text
        Dim i As Telerik.Cms.ICmsWebControl
        For Each i In myList           
             
            Dim mySourceControl As sourceForm = i.LoadControl
             
            Response.Write("data: " & mySourceControl.getData())
             
        Next

    The type sourceForm is the class name of my user control which I reference at the top of my file with:
    <%@ Reference VirtualPath="~/UserControls/sourceForm.ascx" %>

    The getData function of the sourceForm control simple returns the value of it's textbox control:
    Function getData() As String
         getData = myTextBox.Text
          
    End Function

    The problem is that the value of the text field is always an empty string (or whatever the field's initial value to be).  This seems to suggest that using this method, I am not accessing the working instance of the previous page (probably just an new copy of it).

    How can I get the "live" values of the controls on the previous page?

    thanks

  12. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    24 Feb 2010
    Link to this post
    yeah this is what i was asking above... it sounds like you're simply creating a new instance of the previous page...

    the IsCrossPagePostBack SHOULD be true... and the PreviousPage SHOULD have a reference to the page that sent you...

    however, remember these pages do not exist! sitefinity is intercepting the Urls and creating the pages on the fly...

    asp.net doesn't seem to like this regarding cross-post, so the previouspage property is throwing an exception

    is there a workaround?

    EDIT:
    after some hacking, I've discovered that you CAN use the Request.Form to grab the values, either by hard-coding the index (not a good idea) or with the client ID

    for example, I have the control textbox with ID="ValueA" and in the form it is "ctl00$ContentPlaceHolder1$ctl00$ValueA" (inspect the Request.Form.AllKeys property in the debugger to see your control key

    so I can grab its value using Request.Form["ctl00$ContentPlaceHolder1$ctl00$ValueA"]

    however this always returns a string...

    anwyay this sounds really hacky to me, and I don't like it. but if you need a hack fix right away it might work in a pinch. however, I'm sure there is a way to get the PreviousPage in sitefinity... I just don't know what it is :(

    hope this was helpful! I'll let you know if I come up with anything else
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hi SelArom,

    You should better use cookie, session or QueryString as suggested in the previous posts. It is not possible to use Searver.Transfer or some cross methods, because all of them expect physical files, which actually can be created as external pages in Sitefinity.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
13 posts, 0 answered