Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Ajax
I am trying to return value from a modalpopupextendet's textbox to the parent page's textbox without a page refresh.
<html xmlns="" >
<head runat="server">
   <style type="text/css">
        {     background-color:Gray;
              opacity: 0.5;
            padding:6px 6px 6px 6px;
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <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:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalbackground"
         TargetControlID="Button1" PopupControlID="Panel1" CancelControlID="Button3">
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 13-Jun-13 2:51am
Edited 13-Jun-13 4:18am
_Amy at 13-Jun-13 8:13am
Then? What is your question?
maverick12131 at 13-Jun-13 9:19am
Sorry, Updated my question now!!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In your code behind write:
Button2.Attributes.Add("onclick","return ShowData();");
Button3.Attributes.Add("onclick","return ClosePopup();");
Add the following script in the head section of your aspx page:
<script language="javascript" type="text/javascript">
function ShowData()
var txtValue = document.getElementById("TextBox2").value;
return false;
function ClosePopup()
alert('Close button clicked.');
return false;
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.

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

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 13 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100