@Ajax.ImageActionLink(
@Url.Content("~/Content/images/add_icon.png"),
"",//Text in the link
"Add",//alt of the image
"Add",//Title
"Create",//Action
new { },
new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "replace", LoadingElementId = "loading" })
web grids anothers buttons
</div>
***********with taht link i call the Create view :************
the first time i go to create everithing is correct i can save and cancel only one time but when i click create again in the home view this call twice to the controller and the nex time call 4 times and next 8 also make multples post back.
i already check i only have one jquery.unobtrusive-ajax.min.js i read i have to do something like this
<script type="text/javascript">
function finish() { // where can be on form submit or something
$('#replace').load(this.href);
return false;
}
</script>
but i think is not necesary im missing something or how i call the views or when i use ajax to updatetargedid is doing multples times i dont know i hope some body can help me.
Let me make sure I'm understanding this correctly:
On your home view, a user clicks the ImageActionLink which loads the create view
The user submits the form in the create view
The home view is reloaded
Do I have that right? If I do, then the problem has to do with how you're loading the jquery files. Each time you re-render your home view, the three jQuery scripts are being reloaded. You only want the scripts to load one time.
This is because everytiime you load your home page, jQuery binds and event for the click.
Next time you load it again, it is going to bind another event for the same item. You must clear all previous event bindings using jquery to avoid this issue. http://api.jquery.com/unbind/
i make the unbind to all the events in homepage also in create view and do exactly the same thing. i make unbid to each event and for make sure i make unbind to all events but nothing hapens, another idea
I think you need to unbind it before you load the new view. Write a small script to unbind all events on each view and call it via OnComplete option of AjaxOptions. This will ensure you are binding and unbinding events from the same view before replacing
the view with new one.
Also use Chrome developer tools to track your network activity and see how your AJAX calls are flowing. Use console.log() to print out any of the debugging information to chrome javascript console.
You can also use Firefox with Firebug to accomplish similar task.
thanks but is calling multiples times, i do what you say i can find the problem. If i use this
<script type="text/javascript">
$(function () {
$('#gf').click(function () { where gf is the id of my link
$('#replace').load(this.href);
return false;
});
</script>
the problem is solved but not with the post back also if a use this some times i have to click two time to the link. i think im going to change the ajax.actionlink and the ajax.beginform by html.actionlink and html.beginform, i dont want to use Html but
i cant fine the solution
@Ajax.ImageActionLink(
@Url.Content("~/Content/images/add_icon.png"),
"",//Text in the link
"Add",//alt of the image
"Add",//Title
"Create",//Action
new { },
new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "replace", LoadingElementId = "loading" })
web grids anothers buttons
</div>
if this is ur partial view and u are loading it each time
moy7
Member
52 Points
86 Posts
Ajax make multiple calls back
Aug 25, 2012 10:51 PM|LINK
this problem is driving me crazy XD.
i have my home view, here i call a Create view with this:
Home view
<div id="replace">
@Content.Script("jquery.unobtrusive-ajax.min.js", Url)
@Content.Script("jquery.validate.min.js", Url)
@Content.Script("jquery.validate.unobtrusive.min.js", Url)
@Ajax.ImageActionLink(
@Url.Content("~/Content/images/add_icon.png"),
"",//Text in the link
"Add",//alt of the image
"Add",//Title
"Create",//Action
new { },
new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "replace", LoadingElementId = "loading" })
web grids anothers buttons
</div>
***********with taht link i call the Create view :************
<div id="bg">
<div class="viewAdd">
@using (Ajax.BeginForm("Create", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "replace", LoadingElementId = "loading" }))
{
//fields to post back
<div id="logButtonsContainer" class="buttons">
<ul>
<li>
<input type="submit" value="OK" /></li>
<li>@Ajax.ActionLink("Cancel", "Home", new { IncidentID = Session["IncidentID"], Cancel = true }, new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "replace", LoadingElementId = "loading", OnComplete="bg" })</li>
</ul>
</div>
}
</div>
the first time i go to create everithing is correct i can save and cancel only one time but when i click create again in the home view this call twice to the controller and the nex time call 4 times and next 8 also make multples post back.
i already check i only have one jquery.unobtrusive-ajax.min.js i read i have to do something like this
<script type="text/javascript">
function finish() { // where can be on form submit or something
$('#replace').load(this.href);
return false;
}
</script>
but i think is not necesary im missing something or how i call the views or when i use ajax to updatetargedid is doing multples times i dont know i hope some body can help me.
rossisdead2
Participant
1313 Points
300 Posts
Re: Ajax make multiple calls back
Aug 25, 2012 11:55 PM|LINK
Let me make sure I'm understanding this correctly:
Do I have that right? If I do, then the problem has to do with how you're loading the jquery files. Each time you re-render your home view, the three jQuery scripts are being reloaded. You only want the scripts to load one time.
router.samac...
Member
41 Points
22 Posts
Re: Ajax make multiple calls back
Aug 26, 2012 07:15 AM|LINK
This is because everytiime you load your home page, jQuery binds and event for the click.
Next time you load it again, it is going to bind another event for the same item. You must clear all previous event bindings using jquery to avoid this issue. http://api.jquery.com/unbind/
Mark it as answer if it helps.
moy7
Member
52 Points
86 Posts
Re: Ajax make multiple calls back
Aug 27, 2012 04:35 PM|LINK
i make the unbind to all the events in homepage also in create view and do exactly the same thing. i make unbid to each event and for make sure i make unbind to all events but nothing hapens, another idea
router.samac...
Member
41 Points
22 Posts
Re: Ajax make multiple calls back
Aug 27, 2012 05:15 PM|LINK
I think you need to unbind it before you load the new view. Write a small script to unbind all events on each view and call it via OnComplete option of AjaxOptions. This will ensure you are binding and unbinding events from the same view before replacing the view with new one.
Also use Chrome developer tools to track your network activity and see how your AJAX calls are flowing. Use console.log() to print out any of the debugging information to chrome javascript console.
You can also use Firefox with Firebug to accomplish similar task.
moy7
Member
52 Points
86 Posts
Re: Ajax make multiple calls back
Aug 27, 2012 07:15 PM|LINK
thanks but is calling multiples times, i do what you say i can find the problem. If i use this
<script type="text/javascript">
$(function () {
$('#gf').click(function () { where gf is the id of my link
$('#replace').load(this.href);
return false;
});
</script>
the problem is solved but not with the post back also if a use this some times i have to click two time to the link. i think im going to change the ajax.actionlink and the ajax.beginform by html.actionlink and html.beginform, i dont want to use Html but i cant fine the solution
router.samac...
Member
41 Points
22 Posts
Re: Ajax make multiple calls back
Aug 27, 2012 07:46 PM|LINK
Why are you loading jquery inside the div? You should load it outside the replace div. I think this also contributes to your problem.
moy7
Member
52 Points
86 Posts
Re: Ajax make multiple calls back
Aug 30, 2012 11:33 PM|LINK
i try everithing and the only solution is make another view with onle the web gird i want to update nothing else and now is doing only one post back
ossprologix
Member
394 Points
128 Posts
Re: Ajax make multiple calls back
Aug 31, 2012 04:18 AM|LINK
if this is ur partial view and u are loading it each time
this registers ajax functions using live each time. so it might be that
load the scripts in tha master page or segregate it from the partial view
Hope this works for u