ASP.NET Use Javascript to Stop CodeBehind CallHow do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?How do I return the response from an asynchronous call?
Method Does Not Exist error message
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
Unlock My Phone! February 2018
Forgetting the musical notes while performing in concert
Is it possible to create a QR code using text?
Can the Meissner effect explain very large floating structures?
Extract rows of a table, that include less than x NULLs
How much of data wrangling is a data scientist's job?
How badly should I try to prevent a user from XSSing themselves?
What killed these X2 caps?
ssTTsSTtRrriinInnnnNNNIiinngg
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
Which is the best way to check return result?
Is it logically or scientifically possible to artificially send energy to the body?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Why didn't Miles's spider sense work before?
Can compressed videos be decoded back to their uncompresed original format?
What type of content (depth/breadth) is expected for a short presentation for Asst Professor interview in the UK?
Alternative to sending password over mail?
Assassin's bullet with mercury
Mathematica command that allows it to read my intentions
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
What does the expression "A Mann!" means
Is "remove commented out code" correct English?
ASP.NET Use Javascript to Stop CodeBehind Call
How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How to use foreach with array in JavaScript?How do I return the response from an asynchronous call?
I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?
function ShowLoading()
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
javascript asp.net
add a comment |
I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?
function ShowLoading()
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
javascript asp.net
add a comment |
I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?
function ShowLoading()
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
javascript asp.net
I have a DropDownList wrapped inside an UpdatePanel in ASP.net. When you select a different option it first calls function ShowLoading and then proceeds to call the code behind function dropDownMonth_SelectedIndexChanged. I want it to do this. But - is there anyway to keep the structure but when it hits the javascript function there is some javascript code I can write that prevents it from calling the code behind?
function ShowLoading()
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
javascript asp.net
javascript asp.net
edited Mar 8 at 21:42
omikes
3,65682342
3,65682342
asked Mar 8 at 20:48
John DoeJohn Doe
76482144
76482144
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Remove onchange from DropDownList
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
And override generated onchange handler like this
//make sure this code is executed when page is loaded
<script>
var dropdown = document.getElementById("dropDownMonth");
var onchange = dropdown.onchange;
dropdown.removeAttribute("onchange"); //removing original onchange handler
var newonchange = function (ev)
if (ShowLoading())
onchange(ev);
dropdown.onchange = newonchange;
function ShowLoading()
var postBack = /*condition to postback*/;
//..
return postBack;
</script>
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
@JohnDoe one thing I forgot to include in my answer, you have to removeonchange="ShowLoading()"code from element
– Alexander
Mar 8 at 22:32
add a comment |
Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
|
show 1 more comment
return false if you don't want to execute server side code (code behind)
function ShowLoading()
// return true; // Will continue to call code behind
return false; // Stop and don't call code behind
and use return when calling the JS function onchange="return ShowLoading()"
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
</asp:DropDownList>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070783%2fasp-net-use-javascript-to-stop-codebehind-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Remove onchange from DropDownList
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
And override generated onchange handler like this
//make sure this code is executed when page is loaded
<script>
var dropdown = document.getElementById("dropDownMonth");
var onchange = dropdown.onchange;
dropdown.removeAttribute("onchange"); //removing original onchange handler
var newonchange = function (ev)
if (ShowLoading())
onchange(ev);
dropdown.onchange = newonchange;
function ShowLoading()
var postBack = /*condition to postback*/;
//..
return postBack;
</script>
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
@JohnDoe one thing I forgot to include in my answer, you have to removeonchange="ShowLoading()"code from element
– Alexander
Mar 8 at 22:32
add a comment |
Remove onchange from DropDownList
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
And override generated onchange handler like this
//make sure this code is executed when page is loaded
<script>
var dropdown = document.getElementById("dropDownMonth");
var onchange = dropdown.onchange;
dropdown.removeAttribute("onchange"); //removing original onchange handler
var newonchange = function (ev)
if (ShowLoading())
onchange(ev);
dropdown.onchange = newonchange;
function ShowLoading()
var postBack = /*condition to postback*/;
//..
return postBack;
</script>
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
@JohnDoe one thing I forgot to include in my answer, you have to removeonchange="ShowLoading()"code from element
– Alexander
Mar 8 at 22:32
add a comment |
Remove onchange from DropDownList
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
And override generated onchange handler like this
//make sure this code is executed when page is loaded
<script>
var dropdown = document.getElementById("dropDownMonth");
var onchange = dropdown.onchange;
dropdown.removeAttribute("onchange"); //removing original onchange handler
var newonchange = function (ev)
if (ShowLoading())
onchange(ev);
dropdown.onchange = newonchange;
function ShowLoading()
var postBack = /*condition to postback*/;
//..
return postBack;
</script>
Remove onchange from DropDownList
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged"></asp:DropDownList>
And override generated onchange handler like this
//make sure this code is executed when page is loaded
<script>
var dropdown = document.getElementById("dropDownMonth");
var onchange = dropdown.onchange;
dropdown.removeAttribute("onchange"); //removing original onchange handler
var newonchange = function (ev)
if (ShowLoading())
onchange(ev);
dropdown.onchange = newonchange;
function ShowLoading()
var postBack = /*condition to postback*/;
//..
return postBack;
</script>
edited Mar 8 at 22:44
answered Mar 8 at 21:32
AlexanderAlexander
3,1321521
3,1321521
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
@JohnDoe one thing I forgot to include in my answer, you have to removeonchange="ShowLoading()"code from element
– Alexander
Mar 8 at 22:32
add a comment |
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
@JohnDoe one thing I forgot to include in my answer, you have to removeonchange="ShowLoading()"code from element
– Alexander
Mar 8 at 22:32
this doesn't work
– John Doe
Mar 8 at 21:46
this doesn't work
– John Doe
Mar 8 at 21:46
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
alright close enough....i wrapped it in pageLoad method
– John Doe
Mar 8 at 22:10
1
1
@JohnDoe one thing I forgot to include in my answer, you have to remove
onchange="ShowLoading()" code from element– Alexander
Mar 8 at 22:32
@JohnDoe one thing I forgot to include in my answer, you have to remove
onchange="ShowLoading()" code from element– Alexander
Mar 8 at 22:32
add a comment |
Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
|
show 1 more comment
Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
|
show 1 more comment
Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.
Add return false at the end of your ShowLoading function. That should prevent the post back from triggering.
answered Mar 8 at 21:04
Noah BNoah B
1335
1335
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
|
show 1 more comment
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
that doesn't work
– John Doe
Mar 8 at 21:18
that doesn't work
– John Doe
Mar 8 at 21:18
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
function ShowLoading() return false;
– John Doe
Mar 8 at 21:26
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
Alexander's method of capturing and removing the existing onchange method looks like it should work.
– Noah B
Mar 8 at 21:45
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
it doesn't work...could it have something to do with it being in an updatepanel?
– John Doe
Mar 8 at 21:47
1
1
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
I don't have enough reputation to comment directly on Alexander's answer. Put the first block of his code inside a pageLoad() .. code ... function. That is automatically called after an update panel refresh.
– Noah B
Mar 8 at 21:55
|
show 1 more comment
return false if you don't want to execute server side code (code behind)
function ShowLoading()
// return true; // Will continue to call code behind
return false; // Stop and don't call code behind
and use return when calling the JS function onchange="return ShowLoading()"
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
</asp:DropDownList>
add a comment |
return false if you don't want to execute server side code (code behind)
function ShowLoading()
// return true; // Will continue to call code behind
return false; // Stop and don't call code behind
and use return when calling the JS function onchange="return ShowLoading()"
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
</asp:DropDownList>
add a comment |
return false if you don't want to execute server side code (code behind)
function ShowLoading()
// return true; // Will continue to call code behind
return false; // Stop and don't call code behind
and use return when calling the JS function onchange="return ShowLoading()"
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
</asp:DropDownList>
return false if you don't want to execute server side code (code behind)
function ShowLoading()
// return true; // Will continue to call code behind
return false; // Stop and don't call code behind
and use return when calling the JS function onchange="return ShowLoading()"
<asp:DropDownList CssClass="form-control" ID="dropDownMonth" runat="server" AutoPostBack="true" ClientIDMode="Static" Style="display: none" onchange="return ShowLoading()" OnSelectedIndexChanged="dropDownMonth_SelectedIndexChanged">
</asp:DropDownList>
edited Mar 8 at 22:26
answered Mar 8 at 22:00
ElasticCodeElasticCode
2,98611023
2,98611023
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070783%2fasp-net-use-javascript-to-stop-codebehind-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown