0

I have a page with a javascript that dynamically create a controls (radio buttons, text boxes) .

on button (submit) I need to validate the values before proceeding with the event it self .

but , after hitting the button I need to cancel the event if one rule didn't obey. but the page gets refreshed and all my dynamic controls goes so I need to stop any action to a page if one of the rules failed . (save the form)

I believe there is a way such as e.preventDefault(); in javascript .

Please Advise, Many Thanks :)

1 Answers1

0

There are many ways to prevent page refresh But we are not certain what you are talking about, so I'll just Give the regular example That I can Find

Fist your e.preventDefault is not for refresh its just prevent link from opening the URL and i.e as per w3school

      $("a").click(function(event){
  event.preventDefault();
});

Now To prevent a page refresh there are too many example Please take a look at the Given link Please take a look

Community
  • 1
  • 1
Dare Devs
  • 156
  • 1
  • 4
  • 13
  • Thank you, but the problem is I need it in the code behind (vb.net) I need something work like break exit sub , to stay on the same page to save my texts that I wrote on the text boxes after all rules valid. – Mashaeil A. Yusufi Jan 09 '15 at 08:14
  • Then do not allow the postback or use ajax to stay on the page even if the data is send or not – Dare Devs Jan 09 '15 at 12:42
  • One more Thing just use the tag of the html instead of the asp button and put the click event using javascript – Dare Devs Jan 09 '15 at 12:47