Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to return value from a modalpopupextendet's textbox to the parent page's textbox without a page refresh.

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
   <style type="text/css">
        .modalbackground
        {     background-color:Gray;
              opacity: 0.5;
              filter:Alpha(opacity=50);
        }
        .modalpopup
        {
            background-color:White;
            padding:6px 6px 6px 6px;
        }
   </style>
</head>
<body>

    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        &nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="Button" />

        <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup">
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
            <asp:Button ID="Button2" runat="server" Text="Ok" />&nbsp;&nbsp;
            <asp:Button ID="Button3" runat="server" Text="Cancel" />
        </asp:Panel>

        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalbackground"
         TargetControlID="Button1" PopupControlID="Panel1" CancelControlID="Button3">
        </asp:ModalPopupExtender>

    </div>
    </form>
</body>
</html>


on "Button2" click the page does a refresh which I don't want.
Also If I add more buttons to the modalpopupextender and on click of those buttons the modalpopupextender closes

I want the modalpopupextender to close only on the Button2 click event returning a value without refreshing the page
no othe controls on the modalpopupextender should close it.
Posted
Updated 13-Jun-13 3:18am
v2
Comments
_Amy 13-Jun-13 8:13am    
Then? What is your question?
maverick12131 13-Jun-13 9:19am    
Sorry, Updated my question now!!

1 solution

In your code behind write:

C#
Button2.Attributes.Add("onclick","return ShowData();");
Button3.Attributes.Add("onclick","return ClosePopup();");

Add the following script in the head section of your aspx page:
JavaScript
<script language="javascript" type="text/javascript">
function ShowData()
{
var txtValue = document.getElementById("TextBox2").value;
alert(txtValue);
return false;
}
function ClosePopup()
{
alert('Close button clicked.');
return false;
}
</script>


Remember, the ID of your TextBox has to be the ID generated in HTML(view source of your page for client ID) since it is inside a panel. It may change. Alternatively, you can use Control.ClientID property in JavaScript.
 
Share this answer
 
v2

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