Cesar Daniel
Cesar Daniel

Reputation: 737

How do I fill a form using a modal popup?

I have an asp.net address form with a bunch of text boxes (street, number, city, postal code, etc.) and an AJAX modal-popup-extender.

When a button is pressed, an address-book is shown (in the modal popup) where the user can search and select one of his registered addresses. This list is implemented using a GridView and works very well. Each row has a link-button like this:

<asp:LinkButton ID="AddressNameLinkButton" runat="server"
                CausesValidation="false"
                CommandArgument='<%# Container.DataItem("ADDRESS_ID") %>'
                CommandName="Select"
                Text='<%# Eval("ADDRESS_NAME")%>' />

When the button is pressed, this code-behind runs:

Protected Sub AddressGridView_RowCommand(...) Handles AddressGridView.RowCommand
    Dim ADDRESS_ID As Long = e.CommandArgument
    If e.CommandName.CompareTo("Select") = 0 Then
        'Some code that retrieves the information 
        'of the selected address goes here.
        CityTextBox.Text = City
        PostalCodeTextBox.Text = PostalCode
        'Etc. Etc.
        SearchModalPopupExtender.Hide()
    End If
End Sub

Problem is, while this code hides the modal-popup, it does not fill the address form.

How do I fill the form from the modal popup?

Upvotes: 2

Views: 384

Answers (1)

Cesar Daniel
Cesar Daniel

Reputation: 737

The problem was that the GridView in the model-popup was inside an UpdatePanel (thanks to nunespascal for pointing this out).

To solve this, I added this code:

Protected Sub AddressGridView_RowDataBound(...) Handles AddressGridView.RowDataBound
    Dim AddressNameLinkButton As LinkButton = e.Row.FindControl("AddressNameLinkButton")
    ScriptManager.GetCurrent(Page).RegisterPostBackControl(AddressNameLinkButton)
End Sub

Now when I press one of the LinkButtons in the GridView, the modal-popup closes and the address form is filled

Upvotes: 1

Related Questions