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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -