Click here to Skip to main content
15,887,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanted to create pop up window on click of a button to allow user to select any option in pop up and then the option value selected must be send back to aspx page.. i searched and found out that ajax can do so.. is there anyway i can do using asp.net c# code only.. if so plz provide a sample code or link.
thank you in advance
Posted
Comments
Karthik_Mahalingam 4-Feb-14 0:56am    
select any option?
check box or radio button or list , what it is ???
Codes DeCodes 4-Feb-14 1:03am    
i prefer radio button bcoz only one item is to be selected in popup

Try this

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        var OpenPopup = function () {
            var value = window.showModalDialog("POPUPPage.aspx", 'popup', "dialogHeight:200; dialogWidth:200;  center:yes;toolbar: false;status: 0;scroll:0;unadorned:0;help:no");
            document.getElementById('txtValues').value = value;
        }
    </script>
</head>
<body>
    <form id="frm" runat="server">
    <asp:TextBox ID="txtValues" runat="server"></asp:TextBox>
    <asp:Button ID="btnPopUP" OnClientClick="OpenPopup(); return false;" runat="server"
        Text="LookUP" />
    </form>
</body>
</html>


POPUP Page:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="POPUPPage.aspx.cs" Inherits="POC.POPUPPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var closepopup = function () {

            var temp = '';
            var radiolist = document.getElementById('<%= RadioButtonList1.ClientID %>');
            var radio = radiolist.getElementsByTagName("input");

            for (var x = 0; x < radio.length; x++) {
                if (radio[x].type === "radio" && radio[x].checked) {
                    temp = radio[x].value;
                    break;
                }
            }

            window.returnValue = temp;
            window.close()
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Text="One" />
            <asp:ListItem Text="two" />
            <asp:ListItem Text="three" />
            <asp:ListItem Text="four" />
            <asp:ListItem Text="five" />
        </asp:RadioButtonList>
        <asp:Button ID="btnClose" runat="server" OnClientClick="closepopup(); return false;"
            Text="Select & Close" />
    </div>
    </form>
</body>
</html>
 
Share this answer
 
v2
Comments
Codes DeCodes 4-Feb-14 1:50am    
this code is not showing popup.. instead,, on click of btnClose, window.close() is only executed.. what i did was simply pasting ur code but no response is shown except closing window..
Karthik_Mahalingam 4-Feb-14 4:00am    
create a page and put the first code block
and create a second page (POPUPPage.aspx) and paste the second code block
Codes DeCodes 4-Feb-14 5:24am    
ya karthik.. i had done the same the same but was unaware of window.showModalDialog and document.getElementById('txtValues').value = value; so i initially i thought u r passing txtvalues to popup.. now its crystal clear and btw thanks a lot.. u r real programming guru..
Karthik_Mahalingam 4-Feb-14 5:25am    
welcome & Thanks Agustus Jackson :)
If you don't want to use Ajax, then go for jQuery Dialog[^].

It is very light in weight and useful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900