c# - calling csharp method from javascript -


this question has answer here:

i creating validation using javascript validate pagesize between 1 100.. if errorctr = 0 call gotopage() in codebenhind.. thank in advance.

<script type="text/javascript" language="javascript">     function validatepagesize() {         var pagesize = document.getelementbyid('maincontent_txtpagesize').value;         var errorctr = 0;         if (pagesize == "") {             alert('records per page should valid number');             errorctr++;         }         if (pagesize < 0 || pagesize > 100) {             alert('records per page should between 1 100');             errorctr++;         }         if (errorctr == 0) {             //missing code         }     } </script> 

codebehind:

void gotopage() {     if (txtpagesize.text.trim() != "0" && txtpagesize.text.trim().length > 0)     {         gridview1.pagesize = convert.toint16(txtpagesize.text.trim());         getpohistorybyparameterorderbyponumber();         btnshowall.visible = false;     }     else     {         gridview1.pagesize = 100;         getpohistorybyparameterorderbyponumber();         btnshowall.visible = false;         txtpagesize.text = "100";     }  } 

you can't javascript call, need postback if want run code on server. javascript code runs on client (in other words, in browser). c# code get's run on server. should duplicate c# method doing in client side javascript code.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -