views:

49

answers:

2

I recently "converted" an HTML website to web forms. By convert, I mean I opened the website in Visual Studio 2010, added a web.config file to allow HttpPost protocol, and called it converted. However, my form doesn't want to post to my .aspx page. What am I missing? When I build the app, there is no binary created to deploy to my local IIS (7.5 on Windows 7)

<form name="register2" method="post" action="#" onsubmit="return false;">

Then my $.post is in my $(function() {...

$('form[name="register2"]').submit(function () {
    var $registerForm2 = $('form[name="register2"]');
    if ($registerForm2.valid()) {
        $.post({
            type: 'POST',
            url: 'CreateAccount.aspx',
            data: $(this).serialize()
        });
    } else { //do validation
        $registerForm2.validate();
    }
});

When I submit the form, Chrome tells me the request URL is URL:http://localhost/mysite/[object%20Object] and receives error code 404. The page CreateAccount.aspx does exist.

A: 

You will need to change the extension of your pages to .aspx so the ASP.NET runtime will process it. You will also need the <%@ Page %> directive at the top of the page to indicate the page should be compiled.

Also, you will need to add runat="server" to your FORM tag.

Try adding a new WebForm page to the project to see how it gets set up by default, and verify that that works.

dave thieben
I added page directive and renamed to .aspx `<%@ Page Language="C#" AutoEventWireup="true" %>`. Does it matter that this page is a facebox popup? I added the `runat="server"` attribute to the form and it does 2 things different: does *not* render the name attribute, and *does* render an id of `ctl100`. I added an id attribute and changed the `submit` function to identify the form by id, but it seems to post the same. Something wrong with the page directive?
David
right. ASP.NET automatically generates ID's for you, which causes some pain when using jQuery. I try to use classes to identify DOM elements. It seems like for some reason, jQuery is using the wrong URL to submit the request to. I would put a button the form and the only thing it does is call the `$.post()` code, and serialize the form instead of 'this'. that might tell us something.
dave thieben
No such luck with a button or specifically calling .post with it. The markup for the Facebox div's is in a separate file from the "parent" file. The parent is `index.html` and now the child page is `reg.aspx`. Do you think that matters?
David
See my new answer.
dave thieben
+3  A: 

I see the problem now. the $.post() method doesn't support taking an options object as a parameter.

from the documentation:

$.post('ajax/test.html', function(data) {
  $('.result').html(data);
});

so change your code to be:

 $.post( 'CreateAccount.aspx', $(this).serialize() );

and give that a try.

dave thieben
you win, i got the post i expected. woohoo!
David