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

    Help with coding these radio buttons

    Hello Everybody

    I am creating a website using asp.net and vb.net, I am a beginner so please need your help

    I have 4 radiobuttons...Yes1,No1,Yes2,No2

    If user clicks N01,No2 or any No radio button, I need to display message saying do u want to go back and 2 buttons...1 says YES and other button says No, go back....I want to achieve something like sweetalert(which i really dont know how to)

    (http://t4t5.github.io/sweetalert/ ----by passing a parameter, you can execute something else for "Cancel)

    If it says yes then send an email and close the browser.

    If it says No, go back then load the page.

    But before showing the dialogue box, it has to wait for the user to check radiobuttons of 2groups, I mean if user clicks No1, but doesnot click anything on Yes2 and No2, the message should not be displayed, the popup message should come up only when both the groups of radiobutton have been checked.

    I have written the below code but that doesnot satisfy my condition, any no is clicked message comes up.

    <script type="text/javascript">
    function confirmExit() {
    document.getElementById('<%= hfSendMail.ClientID%>').value = 'No';
    var resp = confirm("You have answered No to one or more of the identification questions,Are you sure you want to Exit?");
    if (resp == true) {
    document.getElementById('<%= hfSendMail.ClientID%>').value = 'YES';
    }
    }
    </script>
    <asp:HiddenField ID="hfSendMail" runat="server" />





    <tr class='welcome'><td class='centre'><span>My Name is:</span><br /><strong> <asp:Label ID="Label1" runat="server" Text=" Jones"></asp:Label></strong></td><td><span>Correct?</span>
    <a class="tooltip"><img src="info.png" /><span><strong>Your Name</strong><br />Sorry if it's not exactly correct to identify you.</span></a><br /> <asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" TextAlign="Left" GroupName="namegroup" AutoPostBack="True" /><asp:RadioButton ID="RadioButton2" runat="server" Text="No" TextAlign="Left" GroupName="namegroup" onchange="confirmExit();" AutoPostBack="true" /></td><td class='centre'><span>The Location <br /> Information is:</span><br /><strong>
    <asp:Label ID="Label2" runat="server" Text="Africa"></asp:Label></strong></td><td><span>Correct?</span>
    <a class="tooltip"><img src="info.png" /><span><strong>Address</strong><br />Click 'Yes' if this identifies your location.</span></a>
    <br /> <asp:RadioButton ID="RadioButton3" runat="server" Text="Yes" TextAlign="Left" GroupName="locationname" AutoPostBack="True" /><asp:RadioButton ID="RadioButton4" runat="server" Text="No" TextAlign="Left" GroupName="locationname" AutoPostBack="true" onchange="confirmExit();" /></td></tr>
    <tr><td colspan='4' class='hrr'></td></tr>
    </tbody>


    Protected Sub RadioButton1_CheckedChanged(sender As Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged

    If (RadioButton3.Checked) Then

    Response.Write("")

    If (RadioButton4.Checked) Then
    Response.Write("")
    End If

    End If
  • #765442
    Hi

    did you tried body onload in your aspx page ?

    call your javascript method from the aspx page body obload.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765446
    In the above code where do u want me to do it..please edit my code and explain me...thanks alot

  • #765449
    Hi Lexi,

    As per my understand the post you want to display alert message with Yes/ No options, the best approach to achieve this task is using ModalPopup extender control in AJAX Toolkit, I have already wrote an article for the same, request you to kindly go through the below link to understand better the same,

    http://www.dotnetspider.com/resources/46217-ModalPopupExtender-with-Yes-No-options-without-postback.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765463
    Hi

    Try this code


    <script type="text/javascript">
    function confirmExit() {
    document.getElementById('<%= hfSendMail.ClientID%>').value = 'No';
    var resp = confirm("You have answered No to one or more of the identification questions,Are you sure you want to Exit?");
    if (resp == true) {
    document.getElementById('<%= hfSendMail.ClientID%>').value = 'YES';
    }
    }
    </script>
    <asp:HiddenField ID="hfSendMail" runat="server" />



    <html>
    <head>
    <title>Lexi Web Application </title>
    </head>
    <body onload="return confirmExit();">
    <form id="Form1" runat="server">


    <tr class='welcome'><td class='centre'><span>My Name is:</span><br /><strong> <asp:Label ID="Label1" runat="server" Text=" Jones"></asp:Label></strong></td><td><span>Correct?</span>
    <a class="tooltip"><img src="info.png" /><span><strong>Your Name</strong><br />Sorry if it's not exactly correct to identify you.</span></a><br /> <asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" TextAlign="Left" GroupName="namegroup" AutoPostBack="True" /><asp:RadioButton ID="RadioButton2" runat="server" Text="No" TextAlign="Left" GroupName="namegroup" onchange="confirmExit();" AutoPostBack="true" /></td><td class='centre'><span>The Location <br /> Information is:</span><br /><strong>
    <asp:Label ID="Label2" runat="server" Text="Africa"></asp:Label></strong></td><td><span>Correct?</span>
    <a class="tooltip"><img src="info.png" /><span><strong>Address</strong><br />Click 'Yes' if this identifies your location.</span></a>
    <br /> <asp:RadioButton ID="RadioButton3" runat="server" Text="Yes" TextAlign="Left" GroupName="locationname" AutoPostBack="True" /><asp:RadioButton ID="RadioButton4" runat="server" Text="No" TextAlign="Left" GroupName="locationname" AutoPostBack="true" onchange="confirmExit();" /></td></tr>
    <tr><td colspan='4' class='hrr'></td></tr>
    </tbody>
    </form>
    </body>

    Protected Sub RadioButton1_CheckedChanged(sender As Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged

    If (RadioButton3.Checked) Then

    Response.Write("")

    If (RadioButton4.Checked) Then
    Response.Write("")
    End If

    End If

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765469
    Please check with Auto post back false because you are writing Javascript so the event will fires if it is set to false and remove the server side coding. Once check that. any issues please let me know.
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


Sign In to post your comments