Answered by:
passing User control Gridview popup to parent page

Question
-
User-308948172 posted
I have this User Control which contains
Gridview - container from what I pass from the parent page Done
TextBox - search item/date from the Gridview Done
inside a modal popup
What I want to know/understand is how can I pass the selected Item from GridView Back to the Parent page which other page can benefits or
How can the parent page gets Gridview selected value.
Note:
This controls well be user for about 10 pages.
Thursday, January 30, 2014 10:00 AM
Answers
-
User1734617369 posted
Hi,
You can add a public property to the user control that returns the selected value that you are interested in from the GridView, like:
Public ReadOnly Property GridViewSelectedItem As Int32 Get Return GW.SelectedIndex End Get End Property
/Johan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 31, 2014 3:25 AM
All replies
-
User-760709272 posted
There is no such thing as a "modal popup" in web technology. Do you mean it is inside a div on top of the same page? Or is the "child" page inside an iframe? Is it a new browser window via window.open? We'll need to know exactly how your page is structured as there are many ways to implement a "modal popup".
Thursday, January 30, 2014 10:15 AM -
User-308948172 posted
Do you mean it is inside a div on top of the same page?
Yes, I do.
<%@ Register Src="~/UserControl/BranchController.ascx" TagPrefix ="uc" TagName="Branch" %> <ajaxToolkit:ToolkitScriptManager ID ="AjaxScriptManager" runat ="server" /> <asp:HiddenField ID = "hidden" runat="server" /> <ajaxToolkit:ModalPopupExtender ID="MPEUC" runat="server" PopupControlID="divPopUp" CancelControlID="btnClose2" TargetControlID="hidden" BackgroundCssClass="modalBackground"> </ajaxToolkit:ModalPopupExtender> <div id="divPopUp" style="display: none;"> <asp:Panel runat="Server" ID="panelDragHandle" CssClass="drag"> <div class="gridContainer"> <uc:Branch ID="Controller" runat="server" /> </div> <div class="closeContainer"> <div class="closeButton"> <asp:Button ID="btnClose2" runat="server" Text="Close" /> </div> </div> </asp:Panel> </div>
Both of my 10 pages uses this kind of User Control
Thursday, January 30, 2014 10:01 PM -
User1734617369 posted
Hi,
You can add a public property to the user control that returns the selected value that you are interested in from the GridView, like:
Public ReadOnly Property GridViewSelectedItem As Int32 Get Return GW.SelectedIndex End Get End Property
/Johan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 31, 2014 3:25 AM -
User-308948172 posted
Im confuse.
so how do I pass it ? to my Parent page?
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) //Passing the SelectedIndex to Parent Page CType(Me.Parent.Parent.FindControl("MPEUC"), ModalPopupExtender).Hide() End Sub
Friday, January 31, 2014 3:41 AM -
User-760709272 posted
If you're using the ModalPopupExtender then all that does is put your modal content in a div on the page (divPopUp in your case) and hide it. When you say to show the modal it just makes that div visible and positions it on the middle of the screen. In terms of your page structure, there is only one page and all of the controls are on it...everything on your page and everything in your popup. So you should be able to access them all server-side as normal, just like the popup isn't even there. Basically there is no "parent"/"child" page relationship, everything is on a single page.
Friday, January 31, 2014 4:45 AM -
User-308948172 posted
If you're using the ModalPopupExtender then all that does is put your modal content in a div on the page (divPopUp in your case) and hide it. When you say to show the modal it just makes that div visible and positions it on the middle of the screen. In terms of your page structure, there is only one page and all of the controls are on it...everything on your page and everything in your popup. So you should be able to access them all server-side as normal, just like the popup isn't even there. Basically there is no "parent"/"child" page relationship, everything is on a single page.
Thanks for clearing it up :)
but how I pass the selected item to a textbox?
Friday, January 31, 2014 5:40 AM -
User-308948172 posted
So I've solve the problem on passing the selected item for the gridview
By wrapping the GridView and my Textbox with Update Panel
<asp:PostBackTrigger ControlID="GridView1" />
However when passing the data the whole refresh, Is it possible to pass the value without refreshing the whole page?
Thanks
Saturday, February 1, 2014 4:03 AM -
User-1818759697 posted
Hi,
For implementing this, you could try to use the session to share the datas between pages, the session state is used to maintain the session of each user throughout the application. Session allows information to be stored in one page and access in another page and support any type of object:
Session["FirstName"] = FirstNameTextBox.Text; Session["LastName"] = LastNameTextBox.Text;
For more information, you could refer to the following links:
http://msdn.microsoft.com/en-us/library/ms178581.aspx
http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net
http://www.aspdotnet-suresh.com/2012/11/aspnet-session-state-example-in-c-vbnet.html
Regards
Sunday, February 2, 2014 10:15 PM -
User-308948172 posted
Hi,
You can add a public property to the user control that returns the selected value that you are interested in from the GridView, like:
Public ReadOnly Property GridViewSelectedItem As Int32 Get Return GW.SelectedIndex End Get End Property
/Johan
I'll give it a try
Tuesday, February 4, 2014 5:54 AM -
User-308948172 posted
Using Property helps me alot
Another Problem occur:
The parent textbox well only change if AsyncPostBackTrigger is triggered.
how can display the value to the textbox im confused
Tuesday, February 4, 2014 8:26 PM -
User-308948172 posted
Solve it By just calling the Update() Method of the UpdatePanel all this are going smooth as planned
Tuesday, February 4, 2014 8:41 PM