javascript - OnClick is not working when i do OnClientClick="function(); return false" -


i have 5 asp:buttons want change css class on when click them "marked". javascript , works fine. want store variable in code behind onclick.

my problem is, when click asp:button refresh page. solved ;return false after onclientclick. when have return false, buttons onclick doesnt fire. need getting these both things work @ same time:

  • page not refreshing when pressing asp:button, same time as
  • onclick needs fire also.

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++;       } 

you cannot prevent refresh page if have intention store value in code behind using asp.net webforms. see related question how stop reload page when click button?


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -