ASP.NET: OnServerClick event handler not called if using onclick

后端 未结 8 1676
囚心锁ツ
囚心锁ツ 2020-12-05 21:35

I have a peculiar problem here and I can\'t by my life figure out what the solution is. Note that the following code is not dynamically created, but just immediatel

8条回答
  •  时光取名叫无心
    2020-12-05 22:09

    The accepted answer is not perfect. If you do not use type="button", the web page will do postback even you have clicked cancel. The correct and easiest way is to take advantage of short-circuit evaluation and do this hack: replace ; with && !, like below.

    The output will look like this:

    It gives correct return value because true && !undefined will return true and undefined will be evaluated and false && !undefined will return false and undefined will NOT be evaluated which is exactly what we want.

提交回复
热议问题