jQuery running C# code after other codes -


i have click event on button runs code in c# put c# code in jquery using @{...} however, codes in @{...} runs after other codes.

html code:

   <button type="submit" id="testregex" class="btn btn-default">test regex</button> 

jquery:

 $("#testregex").click(function () {             @{                 var testdata = request["testdata"];                 var expression = request["regexpattern"];                 string regexmatchresult = "no match";                 string datematchresult = "no match";                  if (!string.isnullorempty(testdata) || !string.isnullorempty(expression))                 {                     bool regexmatch =                         system.text.regularexpressions.regex.ismatch(testdata, expression, system.text.regularexpressions.regexoptions.ignorecase);                     bool datematch = false;                      foreach (var item in system.text.regularexpressions.regex.matches(testdata, expression))                     {                         datematch = string.compare(item.tostring(), testdata, true) == 0;                     }                      regexmatchresult = regexmatch ? "regex match" : "no match";                     datematchresult = datematch ? "date matches" : "no match";                 }               }              $('#regexmatch').text("@regexmatchresult");    //             $('#datematchresult').text("@datematchresult"); // these codes run before codes above          }); 

this part should @ top

@{                 var testdata = request["testdata"];                 var expression = request["regexpattern"];                 string regexmatchresult = "no match";                 string datematchresult = "no match";                  if (!string.isnullorempty(testdata) || !string.isnullorempty(expression))                 {                     bool regexmatch =                         system.text.regularexpressions.regex.ismatch(testdata, expression, system.text.regularexpressions.regexoptions.ignorecase);                     bool datematch = false;                      foreach (var item in system.text.regularexpressions.regex.matches(testdata, expression))                     {                         datematch = string.compare(item.tostring(), testdata, true) == 0;                     }                      regexmatchresult = regexmatch ? "regex match" : "no match";                     datematchresult = datematch ? "date matches" : "no match";                 }               } 

and in script tag

 $(document).ready(function(){      $('#regexmatch').text("@regexmatchresult");    //      $('#datematchresult').text("@datematchresult");        $("#testdata").text("@testdata ");       $("#regexpattern").text("@expression ");   }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -