So what i have is a web application that uses c# code and javascript code. My javascript code generates some information dependant on the users input. Once this is finished it is saved using a ASP button. Attached to the asp button is a on client click and a on click event. the Javascript code validates the code and makes sure that the string that has been created is valid. If not a error message is sent to a hidden label. The C# code then checks that label and if it is empty (if there was no problem with validation) it executes the C# code. If it has a value inside then the error message from the hidden label is passed to a visible label using the c# code and shown to the user.
However if the error message is shown the page in automatically reloaded (as it is a button click event this always happens). and the users inputs are cleared from the screen.
Is there any way i can stop the page from reloading when the error message is shown?
CODE
Javascript:
if (goalnum > 0 && blocknum > 0 && playernum == 1 && goalnum == blocknum) {
mapsave = JSON.stringify(map);
document.getElementById('<%=mapsave.ClientID %>').value = mapsave;
}
else {
document.getElementById('<%=lblError.ClientID %>').value = "Your map must have one and only one player, one or more blocks, one or more goals and the number of blocks must match up with the number of goals";
}
C#
protected void btnSave_Click(object sender, EventArgs e)
{
if (mapsave.Value.ToString() == "")
{
lblResult.Text = lblError.Value;
}
else
{
AddNodeToXMLFile("filepath.xml", "TileMaps");
}
}
Do you
return falseon the button click? If not, even if validation has failed a new Post will fire.Can you post the code perhaps?