0

I have something I'd like to attempt, but am unsure of the best path to accomplish it. I have a page, say default.aspx, that creates some content. I also have a second page, say input.aspx, that creates a small select box. This box is to be loaded via ajax on a chang emade on default.aspx. However, I also need this box to initial load in the codebehind of default.aspx.

Example: 1. default.aspx codebehind creates content and loads input.aspx in the codebehind 2. field changes on default.aspx and input.aspx is changed via ajax using Jquery

However, I cannot seem to find the best possible way to load a second ASP.NET page into the codebehind of the initial page. I was considering using an HttpWebRequest object, but am not sure the syntax. Any help would be appreciated.

Thanks!

At Request of @Mbeckish

What I need to happen is outlined below step-by-step

  1. default.aspx loads with content generated from codebehind

  2. Also in codebehind, a select box is loaded (I have this in a separate input.aspx file now. This is the step I need help with.)

  3. default.aspx response is returned and displayed on client

  4. user changes a form value on default.aspx

  5. the select provided by input.aspx is reloaded from server (I currently use a JQuery ajax request to allow this)

steventnorris
  • 5,656
  • 23
  • 93
  • 174
  • If you want the select box to appear in the default.aspx page, why did you place it in a separate page (input.aspx)? – mbeckish Jun 11 '14 at 13:10
  • @mbeckish I need to be able to ajax the input.aspx page in an onchange event in default.aspx. – steventnorris Jun 11 '14 at 13:12
  • Yes, you can use jquery to manipulate the html in default.aspx. – mbeckish Jun 11 '14 at 13:13
  • @mbeckish I don't need to manipulate the html clientside with jquery, i need to ajax a page that uses server-side code to pull from a db. This is why I had a separate page for input.aspx, for ajax purposes. – steventnorris Jun 11 '14 at 13:22
  • Can you explain what you mean by "ajax a page"? What is the sequence of events you are trying to achieve? 1) User visits default.aspx 2) User edits a field on default.aspx 3) ??? – mbeckish Jun 11 '14 at 13:24
  • @mbeckish that's in the OP above. It follows Example: Do you need further information that what is presented? – steventnorris Jun 11 '14 at 13:27
  • Yes, I'm saying that your post is confusing, probably because you are mixing some concepts. Please state as explicitly as possibly what the user should see, without getting bogged down in the details of how you want to accomplish it. – mbeckish Jun 11 '14 at 13:29
  • Here's why your example is confusing. "2. field changes on default.aspx and input.aspx is changed via ajax using Jquery". At the point when the user is on the default.aspx page and is editing the field, the input.aspx page does not exist - only 1 page at a time is loaded in the user's browser (unless you really want @Oscar's solution of using frames to load two pages at once). So the question is what do you really mean by this? Do you want the user to be redirected to input.aspx? Do you want the user to stay on default.aspx, but have a dropdown box appear via ajax? Something else? – mbeckish Jun 11 '14 at 13:34
  • @mbeckish I've added a second step-by-step section for you. – steventnorris Jun 11 '14 at 13:40
  • @mbeckish I'm aware of the fact that only one page loads at once. My question is how to load the response from a seocnd page into the response of the first page using codebehind. I believe this can be accomplished with an HttpWebRequest, but wanted to seek advice since this is not something I have done before. – steventnorris Jun 11 '14 at 13:41
  • No, you don't want to try to take the HTML from an entirely separate page (input.aspx) and inject it into default.aspx. That is where we are all getting confused. Is there a reason why you can't just put the select directly in default.aspx, thus eliminating the need for step 2, and then manipulate it with ajax (to achieve step 5)? – mbeckish Jun 11 '14 at 13:45
  • @mbeckish Yes, I absolutely have to be able to use an ajax request to load index.aspx in an onchange event in default.aspx. I also have to load the response from index.aspx into the codebehind of default.aspx. – steventnorris Jun 11 '14 at 13:46
  • You haven't explained why you need to do this extraordinary step. – mbeckish Jun 11 '14 at 13:47
  • @mbeckish The explanation as to why is a small part of a large structure. I simply need to know how to accomplish that which I've outlined. – steventnorris Jun 11 '14 at 13:49
  • It's difficult to get good answers for an abnormal solution, especially when the motivation for it can't be described. Good luck. – mbeckish Jun 11 '14 at 13:50

2 Answers2

1

Sounds like your second page 'input.aspx' should really be a UserControl (.ascx file), which you dynamically load (using Page.LoadControl(...)) in your default.aspx page.

Wim
  • 11,998
  • 1
  • 34
  • 57
  • Can I then ajax the control in via jquery in an onchange event? – steventnorris Jun 11 '14 at 13:11
  • 1
    @steventnorris You could use an UpdatePanel instead of jQuery AJAX to get the control and avoid full postback. Generally when you create reusable snippets of a page, you put them in User Controls instead of as pages. – mason Jun 11 '14 at 13:58
  • Thanks. Do UpdatePanel's work with ASP.NET 2.0? Also, would you be willing to give a small example and/or a link to some tutorial? I haven't used update panels before. – steventnorris Jun 11 '14 at 14:02
-1

What you need is to add an iframe to default1.aspx and set it's src property to be the other page

<iframe src="otherPage.aspx"></iframe>

http://www.w3schools.com/tags/tag_iframe.asp

Oscar
  • 13,594
  • 8
  • 47
  • 75