You must Sign In to post a response.
  • Category: ASP.NET

    Confimation in


    I have two boxes in, say txt1 and txt2 accepting numeric data.
    My requirement is that both textboxes can have values or any one of them has value.
    I wan to show a confirmation message to the user to save or not while leaving the txt2. txt2 might have value or not. If user choose to save the the value will be saved in the database.
    I can do this with the use of button. But I don't want to use button. i WANT TO DO THIS ON TXT2 LEAve event.
    Again txt2 might have value of not. but message will be shown after loosing focus on txt2.

    Binay Kumar Prasad.
  • #764693
    Add below code in your page load event,

    txt1.Attributes.Add("OnBlur", "return validate()")

    And create a validate function like below,

    function validate()
    if (document.getElementById("<%=txt2.ClientID %>").value == "") {
    alert("txt2 can not be blank");
    document.getElementById("<%=txt2.ClientID %>").focus();
    return false;
    return true;

    Asheej T K

  • #764700
    Hai Binay Kumar Prasad,
    You can use the onblur event for each of the textbox's and then write the code to check whether the textbox is empty or not.
    Below is the code snippet which can be used:

    function CheckForEmptyStringValue()
    var txt1 = document.getElementById('txt1').Value();
    var txt2 = document.getElementById('txt2').Value();
    if(txt1 == '' || txt2 == '')
    alert('please enter in either of the textbox');

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #764704
    1. Design your text boxes (textbox1 and textbox2).
    2. you can do this in two type events (onchange or OnBlur)
    3. Write the javascript for the validation
    4. If you are going to use the server side control. you have to assign the javascript as attribute

    textbox1.Attributes.Add("onchange", "Myvalidation()")
    textbox2.Attributes.Add("onchange", "Myvalidation()")

    5. In the javascript you have validate what ever your want.

    function Myvalidation()
    // Your validation code ...

    By Nathan
    Direction is important than speed

  • #764712
    Dear All,

    I think that you have not understand my requirement.
    My Requirement is that whenever i press tab or enter in the txt2, it will prompt for a confirmation message and if user choose yes the data will save in the database. But txt2 might have value or not but my action will be on tab or enter in the txt2.

  • #764718
    You can check the key in the keypress event

    <input type="text" onkeypress="Myfunction(event)"/>

    function Myfunction(event) {
    var key = event.keyCode;
    // Check the key is for tab or enter
    // then call conformation window

    You can make do the save call using the the following code

    var r = confirm("Press a button!");
    if (r == true) {
    // Make ajax call for save
    // OR
    // Return true for make server side call
    } else {
    // return false

    By Nathan
    Direction is important than speed

  • #764852
    Simply use Javascripts 'onblur' event and call confirm method, The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.
    A confirm box is often used if you want the user to verify or accept something.
    see below snippet

    <p>Click the button to display a confirm box.</p>
    <button onclick="myFunction()">Try it</button>
    <p id="demo"></p>

    function myFunction() {
    var txt;
    var r = confirm("Press a button!");
    if (r == true) {
    txt = "You pressed OK!";
    } else {
    txt = "You pressed Cancel!";
    document.getElementById("demo").innerHTML = txt;


    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765850
    Nice discussion. I read these one by one and also will use at the time of need. Really, these are helpful to users. those have an idea regarding can understand easily by reading. I am a web hosting user hosted my website through hosting. So I have some idea regarding Thanks a lot.

  • Sign In to post your comments