Reputation: 21
i have 5 asp:buttons that i want to change css class on when i click them so they are "marked". I do this with javascript and it works fine. But i also want to store a variable in code behind with the onClick.
My problem is, when i click my asp:button it refresh the page. I solved this with ;return false after my OnClientClick. BUT when i have return false, the buttons OnClick doesnt fire. So i need help with getting these both things to work at same time:
html
<asp:Button ID="Button1" runat="server" Text="1" OnClick="button1_Click" OnClientClick="change_select(this); return false;" CssClass="button black"/>
javascript
function change_select(objs) {
$('.darkgray').removeClass('darkgray').addClass('black');
objs.className = "button darkgray";
}
code behind
int[] answerArray = new int[28];
int answer = 0;
int currentQ = 0;
protected void button1_Click(object sender, EventArgs e)
{
answer = 1;
}
protected void buttonNext_Click(object sender, EventArgs e)
{
answerArray[currentQ] = answer;
currentQ++;
}
Upvotes: 1
Views: 2379
Reputation: 198
You cannot prevent to refresh the page if you have intention to store a value in the code behind using ASP.NET Webforms. See this related SO question How to stop to reload page when click the button?
Upvotes: 0