I currently have a small SQL query which works good on submission.
@{
if(CurrentContext.Page.IsPostBack){
var query = "UPDATE Entry_Data SET VoteCounter = VoteCounter + 1 WHERE ID =" + CurrentNode;
}
}
I need a way of executing the above script without page reload and showing a small javascript message shown below. As things stand, the IsPostBack is executed and javascript message ignored.
<input type="Submit" id="vote-btn" value="Vote for me" />
<div class="success">Thanks!</div>
For anybody interested.
I managed to fix this by adding the script onto the page itself and posting to itself using AJAX.
It turned out I couldn’t execute the file due to a CurrentContext (something in the CMS) and needed to post to itself and add a page.cshtml?vote into the URL to achieve the result, so the postback didn’t reload the page.
@{
if(CurrentContext.Page.IsPostBack){
...connection
var query = "UPDATE Entry_Data SET VoteCounter = VoteCounter + 1 WHERE ID =" + CurrentNode;
}
}
It should be:
@{
if (!string.IsNullOrEmpty(Request.QueryString["vote"])){
...connection
var query = "UPDATE Entry_Data SET VoteCounter = VoteCounter + 1 WHERE ID =" + CurrentNode;
}
}