prevent postback of HtmlButton in C#

前端 未结 4 494
北恋
北恋 2021-01-15 16:41

I am creating HtmlButton dynamically in .cs file. Adding it to Panel using

HtmlButton b1 = new HtmlButton();
b1.Attribute.Add(\"onclick\",\"javascript:valid         


        
4条回答
  •  孤城傲影
    2021-01-15 17:08

    on the javascript function return true or false and then add the return to your onclick as I show here.

        function validateNclick(me)
        {
           if(allIsOk)
           {
             return true;
           }
           else
           {
             return false
            }
        }
    

    and your attribute.

    b1.Attribute.Add("onclick","javascript:return validateNclick(this);");
    

提交回复
热议问题