0

I have jquery code to validate.

function deneme() {
var url = document.getElementById('ctl00_PostitPanel_frmPostAc_txtLink').value;
var youtubeUrl = url.match(/watch\?v=([a-zA-Z0-9\-_]+)/);
var vimeoUrl = url.match(/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/);
if (youtubeUrl) {
    return true;
}
else if (vimeoUrl) {
    return true;
}
else {
    alert('Şimdilik Sadece Youtube ve Vimeo videolarını paylaşabilirsin.');

    return false;
    }

   };

This codes working great.But I want to prevent insert event.It is showing alert.But then inserting item.And code behind.(My controls inside formview.It is not important.Because function working.)

 Button btnKaydet = (Button)frmPostAc.FindControl("btnKaydet");
        btnKaydet.Attributes.Add("onclick","deneme();");

1 Answer 1

1

Try this

btnKaydet.Attributes.Add("onclick","return deneme();");

Note that I have added return before the function call. If the function returns false, it should not post back

Sign up to request clarification or add additional context in comments.

4 Comments

It worked for a once.But for example I write valid link and then inserted.And then I wrote invalid value but inserted too..
when page is postback it is working.Postback needed everytime ?
This is how it should behave jsfiddle.net/gqvM4 Try changing the url variable value
you are right.I think there is problem in my codes.Your answer was right for my question.Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.