Hi all,
I have a listbox control and a button control in a web page. Once the user clicks the button another web page is opened.
The new web page will accept some data from the user which will be used to databind the listbox in the first web page.
In other words, the two web pages ( the parent window and the child window) are open at the same time. The child page needs to databind a control in the parent page.
Is there a way to do it?
I need some code.
Thx in advance
Update:
I hate to do this.
Looks like I will have to take help of viewstate and session since I cannot figure out any other way.
But some comments from the all stars would have been better.
Here is what I am planning to bind the dropdownlistbox in the parent page from the child page.
1. User keys in data in Parent Page:
Do nothing.2. User clicks the button in Parent Page:
In Parent Page:
Grab the data in a datatable.
Save it in the viewstate and a session object.
Open Child Page.In the Child Page:
From the session, load the datatable in the child page viewstate.
Delete the session.3. User is done with the data entry in the child page and clicks a button to indicate that to the application:
Child Page:
Create a session from the viewstate with the updated data.
Use javascript reload of the parent page.Parent Page:
The page load event of the parent page will collect the data from the session and put back in the viewstate.
Delete the session.
The binding of the listbox can occur with the updated data.The child page can then close itself using javascript.
Regards
aspnetdev2000
![]() |
0 |
![]() |
aspnetdev2000:Hi all,
I have a listbox control and a button control in a web page. Once the user clicks the button another web page is opened.
The new web page will accept some data from the user which will be used to databind the listbox in the first web page.
In other words, the two web pages ( the parent window and the child window) are open at the same time. The child page needs to databind a control in the parent page.
Is there a way to do it?
I need some code.
Thx in advance
Based on your description, It seems that you want to bind the data in parent page according to the operations in child page. If in this case, I suggest you store the data to Session variable and bind data with the Session variable in Parent page and refresh the parent page.
Gary yang - MSFT
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi Gary,
That's exactly what I was thinking. Look at my update.
Is that the best practice considering that opening multiple windows may not be such a good thing after all?
Regards
aspnetdev2000
![]() |
0 |
![]() |
If you can use ajax, a better way would be to use a modal popup control from the ajax control toolkit ... since this control uses a div or panel which is present in the page itself, you will not need to think of storing the values etc .. also on clicking the button, you can directly refresh the page .. since the button is on the same page ...
Thanks,
Ravikanth
Please "Mark as Answer" if you find this post useful
![]() |
0 |
![]() |
aspnetdev2000:Hi Gary,
That's exactly what I was thinking. Look at my update.
Is that the best practice considering that opening multiple windows may not be such a good thing after all?
Regards
If in this case, Please refer to the following code:
//Parent page
//Parent page behind code
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { DataBinds(); } } void DataBinds() { DataTable dt = null; if (Session["dt"] != null) { dt = Session["dt"] as DataTable; GridView1.DataSource = dt; GridView1.DataBind(); } }
//Child page
// Child Page behind code
protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DataBinds(); } void DataBinds() { DataRow dr = null; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("ID", typeof(String))); dt.Columns.Add(new DataColumn("Column1", typeof(String))); dt.Columns.Add(new DataColumn("Column2", typeof(String))); dt.Columns.Add(new DataColumn("NewLetters", typeof(Boolean))); for (int r = 1; r < 10; r++) { dr = dt.NewRow(); dr[0] = r.ToString(); dr[1] = "images/b.gif"; //+ r.ToString(); dr[2] = "Column2" + r.ToString(); dr[3] = true; dt.Rows.Add(dr); } Session["dt"] = dt; Page.ClientScript.RegisterClientScriptBlock(this.Button1.GetType(), "EventPop", "window.opener.location.reload();window.opener==null;window.close()",true); }
![]() |
0 |
![]() |
Hi Gary,
As you can see from my approach, you are partly right in coding it. You are creating the datatable in the child page itself instead of the parent page.
In my approach, the parent page holds the data and the child page only updates a part of it. The updated data is used by the parent page to bind the control in the parent page.
However, it is basically the same, which is using the session object to hold the data for the application.
I will stick to the line I initially suggested if I am not using Ajax.
Regards,
aspnetdev2000
![]() |
0 |
![]() |
aspnetdev2000:Is that the best practice considering that opening multiple windows may not be such a good thing after all?
Do you worry about it will opens multiple windows as you refresh the page or other?
Gary yang - MSFT
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
aspnetdev2000:Is there a way to do it?
I need some code.
I think I can give a sample code to your in my previous post.
aspnetdev2000:Looks like I will have to take help of viewstate and session since I cannot figure out any other way.Actually, you have not to create Session variable. You can also retrieve data from database. Because the parent page will reload as long as you update data in child page.
Gary yang - MSFT
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi Gary,
The code you gave is totally appreciated. Thanks for it.
Secondly, if the parent page is performing an Insert Operation in the Database, then you may not be able to retrieve the data, because the data is not even inserted in the first place. It is only stored in the viewstate of the parent page which when reloaded from the child page will lose the user entries.
That is why, using session is the desired way, isn't it?
Regards,
aspnetdev2000
![]() |
0 |
![]() |