2

I've used jQuery dozens of times with PHP with great success. I'm working on an ASP.NET application and would like to use jQuery in the same manner.

Basically, I've got a masterpage that has the form and a webform that has all the form fields and data. A user can submit the form multiple ways - selection of a drop-down, button, etc. I want to catch all submits and use jQuery to submit the form. While the form is being processed, I want to display a new DIV with some text in it. Finally, I want to replace that div with the new form.

How can I accomplish this with the way that ASP.NET works?

2
  • are you trying to accomplish this without seeing the postback refresh? Commented May 18, 2011 at 18:14
  • @Mutt: Sorry I should have clarified. I want to have access to the results to make changes to the form as needed and load the "new" form. Commented May 18, 2011 at 18:53

2 Answers 2

3

Actually ASP.NET will post-back if you use its built-in JavaScript __doPostBack function. There's no other painless way for doing that.

That means you can use jQuery to handle drop-down lists, buttons or whatever (X)HTML element event and handler's body will invoke __doPostBack.

It's unclear that you want is a full-postback, but a partial one using AJAX.

If you're looking for a solution for sending form values to the server without a full-postback, I believe you've these options:

Anyway, let me give you an advise: ASP.NET works quite different compared to PHP and you'd not try to reproduce some known PHP solutions in ASP.NET. You need to change your mind.

About showing a DIV or anything while something is processed, play with initializeRequest ASP.NET AJAX PageRequestManager:

But that would depend on what AJAX API you're using, because since Microsoft AJAX will be replaced by jQuery in the next times, I'll need to say that you need to do that in some jQuery approach, like creating some $.ajax wrapper so your code will be able to listen when an asynchronous request is going to be made and you can perform actions by handling that situation like showing a DIV or any loading notice.

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

Comments

2

In ASP.NET Webforms formposts aren't as easy as they are in php. If you're new in ASP.NET development try http://www.asp.net/mvc. A common framework which allows you to implement TypedViews (ViewModes), simple request to modelbinding, and so on...

mh, sample:

[HttpPost]
public JsonResult Insert(string name, string vorname) // name&vorname filled by $_POST:)
{
    var @new = new Person { Name = name, Vorname = vorname }
    this.repo.Insert(@new);

    return this.Json(new { success = true, newId = @new.Id });
}

Comments

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.