5

I have this little problem... I have this asp.net website. I have a menu, all done with html and css. So when I click on home, the ajax loads the other content into the specified div element. Working 100%.

In the content that was loaded into the div element, I have a button. An ASP.NET button.

When I click on the button, it gives me a "The resource cannot be found." error.

There must be something I am missing. If you dont understand, heres the ajax:

//Load the Home page on click.
$(document).ready(function () {
    $('.home').click(function () {
        $("#content").load("html/home/home.aspx");
    });
});

Now the aspx page that was loaded into the content div, displays a button, btnAdd:

<asp:Panel ID="pnlAddNewBlog" runat="server">
    <asp:TextBox ID="txtAddNewBlog" runat="server" TextMode="MultiLine"></asp:TextBox>
    <br />
    <asp:Button ID="btnAdd" runat="server" Text="Add" />
</asp:Panel>

When I click on that button, the error appears.

What I want to achieve is to: when the user clicks on the button, the text in txtAddNewBlog gets added into a database. Now this I can achieve using C#... but not if this error is in my way. Any ideas?

3
  • Does html/home/home.aspx exist? Try looking at the network request the browser is sending. Navigate to that URL to ensure it exists. Commented Apr 18, 2013 at 18:41
  • yes, it exists, because the ajax loads all the content in home.aspx into #content and I can see it. but when I click on the botton. This works when I dont have ajax loading the content... but when ajax comes in it does not work any more Commented Apr 18, 2013 at 18:44
  • 1
    Is the #content placed inside some other form ? If yes then you break the html struct when you load the other page. Commented Apr 18, 2013 at 18:52

1 Answer 1

1

The problem is going to be the form that gets created. When you make that request, ASP.NET will build a form whose target is home.aspx, not the full path to it. But you're dumping that form onto an HTML page that's at a different level.

When you do a form post, it attempts to post to home.aspx, relative to where the browser thinks it is, which is two levels up, and it doesn't find it.

I don't know if there's a good way to do this - ASP.NET is not meant to handle this kind of thing. You can do an IFRAME. You can wrap the home.aspx content into a user control, and leave the ASP.NET form on the outer page. Or you may be able to manipulate the form's target so you post to the right place. But I don't think any of those would be a lot of fun.

Sign up to request clarification or add additional context in comments.

2 Comments

so is is better to create webforms and just "Response.Redirect" them and reload the whole page???
My opinion, yes, with the current architecture, best bet would be to actually redirect rather than AJAX-ify it. The user has to deal with page reloads, but most of the web still works that way. If you want to avoid that, I'd recommend building a solution without the ASP.NET WebForms page lifecycle - single-page apps are generally very javascript-intensive, so the architecture would be very different from a traditional WebForms app. Your server code could handle building traditional markup and posts, leaving navigation for client code.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.