Ajax.BeginForm Switches From Async To Sync?
Dec 9, 2010
I'm running into an issue with an async call to the server that only works one time, then it appears to become a synchronous call. Let me try to explain.
It's an MVC 2.0 site, using ASP.NET and Ajax. I'm using the Ajax.BeginForm helper, like so:
<% using (Ajax.BeginForm("Start", null,
new { virtualMachineId = xyz },
new AjaxOptions { UpdateTargetId = "VirtualMachineForm", OnBegin="OnStartingVm" }
)){
[Code]....
Within the updateStartingStatus function, the first part runs every second, every time. However, within the Ajax call, the success result works every second on the first time only. Then on the second time I click on the start button all of the requests queue up. After the starting has completed, about 20 seconds later, I get a bunch of alert windows back to back. So, I can tell that updateStartingStatus runs every second every time, but the ajax call appears to switch to become a sync call after the first time.
I have to fully close it and open it again. The same occurs in IE and Chrome.
One more thing to note is that the updated div (VirtualMachineForm) contains most of the page, including the button being pressed. So it basically replaces the page from under itself. Not sure if that would cause any issues.
Additionally, if I debug in Visual Studio 2010, the call isn't made to the controller action when the issue occurs. So, it appears to be something client-side. I've ruled out any issues server-side.
View 2 Replies
Similar Messages:
Jan 27, 2011
When I put a part of my form in a partial view, all form parts get unobstructive syntax except the form elements in the partial view. The only way I found how to "apply" the unobstructive syntax, is by starting another form inside the partial view.
@using (Ajax.BeginForm("SubmitHandler", new DefaultAjaxOptions()))
{
@Html.EditorFor(m => m.Name)
@Html.Partial("MyPartialView", Model)
}
PartialView:
@Html.TextBoxFor(m => m.SomeContent)
<input class="text-box single-line" data-val="true" data-val-required="This field is required." id="Name" name="Name" type="text" value="">
<input id="SomeContent" name="SomeContent" type="text" value="0">
So only the input element from the View has the unobstructive syntax and the partial view hasn't... Is there a way to apply unobstructive syntax inside a partial view, wich doesn't require you to begin a new form?
View 2 Replies
Feb 5, 2010
I use an updatepanel and I register a handler for endRequest to catch errors: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); On the server an exception is thrown to test the client side. The problem is that in IE and FireFox EndRequestHandler is never called! It works as expected in Opera and Safari. On a simple page with few controls it works as expected in all browsers. What I found out with Firebug is that the response is Content-length: 67, but there is no response (empty tab for response)! The expected response is 53|error|500|Object reference not set to an instance of an object.|
I have not debugged the ajax library precisely but what I have seen is that some code runs to prepare for pageLoading event (maybe because it cannot detect the error?), but there is no information for updatepanels from the response and an error occurs trying to use an object for updatepanels which is null. The error is caught by a try-finally block.
View 2 Replies
Dec 27, 2010
I'm trying to use Ajax.BeginForm() to POST A Json result from my controller (I'm using MVC3). When the Json result is called it should be sent to a javascript function and extract the object using:
[Code]....
View
[Code]....
The strange thing is that the exactly same code works in MVC2 - Is this a bug, or have I forgot something?
View 6 Replies
Jul 9, 2010
I'm using Ajax.Begin form with MVC validation. When I'm in the server code and there's a validation error then ModelState.IsValid is false and that's good.If I have OnSuccess defined in my AjaxOptions why does my OnSuccess function get called when the ModelState is not valid?In my parital view:
using (Ajax.BeginForm("ProfileEdit",
new { controller =
"Account", action =
"ProfileEdit", id =
ViewData["ProfileID"]
}, new
AjaxOptions { UpdateTargetId
= "profileEdit", OnSuccess
= "OnSuccess" }))
In my controller I always just return PartialView();
I just want to display a success message in the view but OnSuccess gets called even if there is a modelstate error. If I try to throw a HttpException then I lose my ValidationSummary and other error messages.
To work around, I'm setting a ViewData["Success"] and displaying the message div in the .ascx if ViewData["Success"] != null.
View 3 Replies
Mar 10, 2011
how to set the form id on an Ajax.BeginForm, i currently have:
[Code]....
This produces the following html:
[Code]....
For some reason it appends the following ?Length=8 onto the action, i've tried moving the id around and removing the @ but then the ID displays form01
I'm using MVC3
View 4 Replies
Jul 15, 2010
Why would a DropDownList switch from Spanish into English when one selects a new item in it? And how does one prevent that from happening?
[Code]....
When you first come to this page after having chosen Spanish as your language, the dropdown is populated with the ListItems texts displaying -- as expected -- in Spanish. But when you go to select another item from the dropdown, all the items come back in English!
When you examine the dropdown before the AutoPostBack (both server-side and in FireBug), each ListItem is properly set, as in
Value="Some English" Text="Some EspaƱol"
whereas **after** the PostBack, it looks like
Value="Some English" Text="The same English"
Why is this happening, and what can I do to get it to keep the Spanish one sees before any PostBacks?
**Notes**:
1. The routine pointed to in `OnSelectedIndexChanged` is currently commented out, so the problem is not there.
2. I added `EnableViewState="true"` to the DropDownList, but that didn't make any difference, so I removed it.
3. As suggested below by Ichiban, I moved setting the `Thread.CurrentThread.CurrentUICulture` from `Page_Load` to `Page_Init()`, but that too didn't make any difference.
View 4 Replies
Jul 14, 2010
is there a way i can file upload using ajax.beginform as i am using jquery dialog and can't use html.beginform
Basically i am implmenting a sort of wizard for initializing website on jquery dialog which need to have ajax there
View 1 Replies
Jan 6, 2011
I have RemoteValidators working correctly on Html.BeginForm. However when I turn this from in Ajax.BeginForm and perform following:1. Type in Textbox whose viewModel Property is bound to a Remote Validator RC2 MVC3
2. Press Submit Button immediately.3. What I observe = data is saved before it the validation completes.
4. On Server UpdateModel works and it finds no issues (even though the remote Validator would have noticed the problem).
View 1 Replies
Dec 23, 2010
[Code]....
I have the above code, on the get method I do the following.
[Code]....
It only hits the index once after loading the page. It never goes to the index method.
View 2 Replies
Oct 2, 2010
so I am using a foreach loop to iterate through comments. The comment section is wrapped inside "Comments" div. My function **DeleteComment** fetches comments again once you delete a comment and rebinds it to the control. However, after you delete a comment, anytime you try to delete another comment, the commentId of the very first deleted comment would keep getting passed to **DeleteComment** function instead of the passing the commentId of the comment you are trying to delete. If you refresh the page, then you can delete ONE comment again, and the same problem if you try to delete another.
View 1 Replies
Mar 22, 2010
I am trying to make an AJAX Form work correctly with Client Validation, but I can't seem to figure out how to make it work together.Currently I have a view like this:
[Code]....
My model:
[Code]....
The client validation works on the Required and Stringlength attributes, but if I put an incorrectly formatted email, it still returns successful. Is there a special way to do the regular expression attribute? Or am I doing it wrong?
View 8 Replies
May 20, 2010
Using the following Ajax.BeginForm, it`s not reaching the controller. What is wrong with the following code? The $('#editForm').submit(); is reached but after that, it doesn`t reach the action.
[Code]....
View 4 Replies
Aug 25, 2010
can i have more than one AjaxOptions in Ajax.BeginForm targetting different controls?Actually I want to exchange data between two listboxes placed in a single ajax.beginform.
View 1 Replies
Feb 19, 2010
I'm using VS2008 and .net 3.5. I want to invoke a javaxcript hide() when user clicks the Search button and before running the action code. Previously I didn't need to run the javascript yet I use the (Html.BeginForm.
After I modified the code to use the Ajax.BeginForm I get the Error below. "SearchSurveyResults" is my action's name and "SurveyResults" (The file name is SurveyResultsController.cs )is the controller name that contains the action. The Javascript that I want to run when user clicks the Search button is hide().
What am I doing wrong here? Why is it looking for a /SurveyResults.aspx file? SurveyResults is the name of my controller where the form submit should send ti one of its action.
<% using (Html.BeginForm("SearchSurveyResults", "SurveyResults", FormMethod.Get, new Dictionary<string, object>() {{@"class", "communitysearch"}}))
{ %>
<fieldset>
<legend>Search by Keyword</legend>
[Code]....
Server Error in '/' Application.
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. review the following URL and make sure that it is spelled correctly.
Requested URL: /SurveyResults.aspx
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
View 3 Replies
Mar 19, 2011
I've got problem with Ajax.BeginForm in ASP.MVC 3. I want to search textbox for my database. So I've got this code in my Index view:
[Code].... Which calls this method in controller, which return detail partial view of patient
public ActionResult GetPatientByRC(string RC)
{
IPatientService svc = new PatientService(_PacientRepository);[code]....
after clicking on submit button, I'll get partial view open in new webpage (not in GetPatientByRC div). Does somebody know what is wrong?
View 1 Replies
Feb 25, 2010
I have an Ajax form with a single input and a button. On submit, the form should only post the entered value to an action method. My form is correctly posting to the User controller's Log method but when done, the page redirects to /User/Log.
How can I avoid this?
[Code]....
View 1 Replies
Oct 14, 2010
I got a problem with client side validation not firing, after reading many posts I believe it as to do with the HTML being loaded "afterwards". But I can not seem to find any solution.You got any ideas how to solve it?
[Code]....
[Code]....
[Code]....
View 1 Replies
Apr 19, 2010
I have a situation where I need to display an actual error/exception that happened during processing after the OnFailure event of the AjaxOptions class fires. Is this possible? I know the OnFailure allows me to write a method that can display a custom error message. Instead of this error message, I'd like to display the actual exception.
Here is my code for the ajax form init.:
[Code]....
And then here is my Javascript method:
[Code]....
As you can see, I am currently displaying an errorMessageDiv which has the code:
[Code]....
I would love it though if I could show them the actual Exception message (which i have wrapped) so I can tell them the exact cause of error.
View 3 Replies
Mar 3, 2010
whenever I sort on a column it resets all my toggled columns back to visible. Is there a way to resort and keep the toggled columns that were selected as hidden to stay hidden?
View 2 Replies
Feb 10, 2010
I am wondering how i can use JQuery validation plugin in Ajax Beginform for client side validation.
Here is my code:
[Code]....
Controller Method:
[Code]....
I am wondering how i can use JQuery validate plugin before the controller method is called. These are the validation rules.
Password field is required field. Minimum length is 6. I am not sure where to specify this
[Code]....
. Ex:
[Code]....
View 3 Replies
Mar 20, 2011
Can I call Ajax.BeginFrom from a custom helper method ?
AjaxHelper is not available in a custom helper method, so I tried to pass the "Ajax" available in ViewPage to Helper method while calling it, but then in method, BeginForm is not available on that passed "Ajax" parameter.
View 1 Replies
Sep 28, 2010
I have a webform in which i am using Ajax.BeginForm.
But due to this my client side required fields are not working.
View 1 Replies
Apr 1, 2011
I using this Ajax.BeginForm
<% using( Ajax.BeginForm( "Create","Mandate",
new AjaxOptions( ) {
OnSuccess = "GoToMandates",
[code]...
View 1 Replies
Oct 12, 2010
Currently I have a comments section integrated into a blog I am writing. The comments are Ajaxified, when you post a comment the comment list auto updates with the comment you just added. Everything is working great but I would like to do some cleanup after a comment is successfully posted. Specifically I would like to disable the textarea and submit button which I would have no issues doing through javascript by using the AjaxOption OnComplete parameter. To avoid double posts or just plain abuse. I know I will need other safegaurds as well but this is my first step. The thing is Ajax.BeginForm does not give the form an id or name so I can not reference the form in javascript. Is there a workaround here? Can I disable these form controls from the controller?
Here is my code.
[Code]....
View 2 Replies