Popup Control for ASP.NET Web Forms - How to return values from the content collection and close the pop-up window on the client or server
This example demonstrates how to add an editor to the popup control's content collection, get the editor's value, and close a pop-up window on the client or server.
Create a popup control, use its ContentCollection property to specify the control's content, and populate a pop-up window with a text box editor and two buttons.
<dx:ASPxPopupControl ID="popup" runat="server" ClientInstanceName="popup">
<ContentCollection>
<dx:PopupControlContentControl runat="server">
<dx:ASPxTextBox ID="textBox" runat="server" ClientInstanceName="textBox" />
<table>
<tr>
<td>
<dx:ASPxButton ID="btnClient" runat="server" Text="Client" AutoPostBack="False" ClientInstanceName="btnClient">
<ClientSideEvents Click="OnBtnClientClick" />
</dx:ASPxButton>
</td>
<td>
<dx:ASPxButton ID="btnServer" runat="server" Text="Server" OnClick="btnServer_Click" />
</td>
</tr>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
To close the pop-up window, call the control's Hide method on the client side or set the ShowOnPageLoad property to false
on the server side.
function OnBtnShowPopupClick() {
popup.Show();
}
function OnBtnClientClick(s, e) {
popup.Hide();
ShowInfo('Client', textBox.GetText());
}
function ShowInfo(closedBy, returnValue) {
alert('Closed By: ' + closedBy + '\nReturn Value: ' + returnValue);
}
protected void btnServer_Click(object sender, EventArgs e) {
popup.ShowOnPageLoad = false;
string startUpScript = string.Format("ShowInfo('Server', '{0}');", textBox.Text);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ANY_KEY", startUpScript, true);
}
You can also get the editor's value to display it in an alert message.
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)