How to databind control in one web page from another web page

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
3/15/2009 10:35:50 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

8 Replies
1202 Views

Similar Articles

[PageSpeed] 54

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
Gary
3/17/2009 6:13:34 AM

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
aspnetdev2000
3/17/2009 7:26:20 AM

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
gravyty
3/17/2009 7:34:35 AM

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

 <form id="form1" runat="server">
    <div> 
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
         AllowSorting="True" >
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
            <asp:CheckBox ID="CheckBox1" runat="server" />
            <asp:Label ID="ID" runat="server" Text='<%#Eval("ID") %>' style="display:none"></asp:Label>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="lb_strSSNum" runat="server" Text='<%#Eval("NewLetters") %>' style="display:none"></asp:Label>
        </ItemTemplate>
        </asp:TemplateField>
            <asp:BoundField DataField="Column1" HeaderText="Header1" SortExpression="Column1"/>
            <asp:BoundField DataField="Column2" HeaderText="Header2"/>
        </Columns>
    </asp:GridView>
        <input id="Button1" type="button" value="button" onclick="window.open('Upload.aspx')"/></div>
    </form>

 //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

    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </form>

 // 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);
    }
 

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
Gary
3/17/2009 8:00:53 AM

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
3/24/2009 5:39:45 AM

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
Gary
3/24/2009 6:25:49 AM

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
Gary
3/24/2009 6:39:42 AM

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
aspnetdev2000
3/24/2009 6:56:09 AM
Reply:

Similar Artilces:

how to navigate the url page in one web application page to another web application page
In my project one solution have 2 web apllications in one folder.like 1.webapplication1 2.webapplication2. in firt webapplication1 i created one aspx page like sample.axpx. in second webapplication2 i created one aspx page like sample2.aspx... in sample2.aspx page have hyperlinl. I need to navigate this hyperlink when i click it go to the sample.axpx. how can i write navigate url for this...help me. ..thanks  As i understand u, you need Multi Project soltuionsee this link, http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/archive/2006/02/19...

How to open another web page from one web page
Hi, I am writing an asp.net(C#) 2.0 web page with a link to another web page by clicking a button control on the page, so how can I link it in the codes? I cannot access another aspx page class within the current aspx page class.  Thanks If you need to re-direct the user to another page after pressing your Button, then use the Response.Write method like so: Response.Redirect("~/Default.aspx")Thanks, EdMicrosoft MVP - ASP/ASP.NET 1) Response.Redirect( "Destination PageName");2) Response.Transfer("Destination PageName");3) Hyperlink(  set Url="...

Is it possible to embed part of one web page into another web page?
Any answers will be highly appreciated.  Thanks. If you can adjust the page you want to embed onto the other page, you could use a .ascx (web forms control).  Then you can add controls to it and just drag and drop it using VS.NET from the Solution Explorer window to the webform.  You can then also embed it onto other pages in that same web project easily by drag n drop.  I hope this helps, it's not exactly a portion of a web page but may be an acceptable alternative for you.Rachel AppelMVP - ASPInsider In order to better answer this, I could use some details as ...

Can my web page with a form submit to other web pages forms?
I was wondering if I created an aspx page that had a form on it that I could use the submit button to submit this form's contents to other web pages forms(servers accepting those form's data). I am thinking this would be a great way to update data on particular web pages without having to actually visit those similar web pages. Any ideas, examples would be much appreciated. Thanks in advance.  Yes you can.  It's called Cross Page Posting: http://msdn2.microsoft.com/en-us/library/ms178139.aspxAlso: http://msdn2.microsoft.com/en-us/library/ms178140.aspx might ...

link a web page to another web page?
I have a web page with my banner and buttons for my site on it. I want to add this to all of my pages. Instead of copying a pasting that to every page. Is there a way i can link the pages to the banner page? Thanx use ascx?:) Or you could create a template page. That is: Create a page inherited from System.Web.UI.Page and place your banner and buttons in this and then have all your other pages inherit tis custom page instead of System.Web.UI.Page. ...

i web page referencing another web page
Can one web page reference a control on another web page? EX. a page is brought up with a number of textbox controls. Using a hyperlink one can pop up a nother page with the calendar control. Select a date from the calendar control and place the value back in the previous page. Can this be done and how? Use a Page.RegisterClientScriptBlock to open a window, with a javascript string like this: "<script language=Javascript>window.open('my_url.aspx','window_name','left=100,top=100,width=200,height=500,toolbar=no,scrollbars=yes,resizable=yes');</script>" Then you can s...

All web pages hang on web server when one of the web pages calls a run away sql query
Hi: We have a Windows 2003 dedicated web server running the .NET Frameworks 1.0 and 2.0.  We have a SQL Server cluster running SQL Server 2000.  Unfortunately, we do not have a test environment.  I have 2 .NET web sites in production.  My coworker has a voting .NET web page using AJAX on the same server.  The coworker wrote a query that was not indexing properly and when the page fired the query...the cluster went to almost 100% utilization.  My two web pages would hang and show a blank white page on the default.aspx.  Neither of m...

how can you display another web site's web page in your web page without leaving your site
Can you display another web site's web page in your web page without leaving your site? I know you could use a frameset with .asp, but it looks like Visual Web Delevoper 2005 does not have any controls to setup a frameset. Any help, that would point me in the right direction would be great. Thanks Patrick     With screen scraping 4GuysFromRolla.Com: Screen Scrapes in ASP.NEThttp://www.4guysfromrolla.com/webtech/070601-1.shtmlThanks,Teemu KeiskiFinland, EU Thank you. This information was a great help!!! Thanks again Patrick...

activating new web page from another web page
Hello all. I'm trying to activate a web from from another web form. I meen, something like: public class RptReq : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { // Put user code to iniialize the page here Report rpt = new Report(); rpt.Page_Load(sender,e); } //Web Form Designer generated code } Report is another class in my name space. Can I get the right way to do it? Best regards to all. Shlomi <p><a target="_blank" href="sdfdf.asp">rdfgfdg</a></p> ...

diplay a web page into an area of another web page
How can I display a web page into an area of an other web page? I am using asp.net 2.0 and would like to avoid frames, but the functionality I need is just the one of a frame. Thanks Giancarlo Stinga You can use an iframe:http://www.mike-levin.com/iframes/ Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! DarrellNorton:http://www.mike-levin.com/iframes/ Wow!  Thanks for the extremely helpful link, Mr. MVP Moderator.  And we are supposed to look up to you guys...  Giancarlo: Here are some useful and releva...

how to open a web page in form of a popup web page
Hello, I have two web pages, let say. Page A : With a Button on it. PAge B: with some info. Now I need to: When I click on the Button of page A.Page B must open in a pop up window.  I can do this but problem is this when I clicked on the button for first time it does not show me any thing and when I clicked on the button for second time then It shows me Page B .My code is as follow:  1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!this.Page.IsPostBack) 4 { 5 6 } 7 else 8...

Web page opens second web page, how does first page know when the second one closes?
I have an app written in ASP.NET where one of the web pages opens up a web page in a second window.  When this second web page closes, the first web page needs to update its data.  How do you do this? You can have the child window call a parent method when the user clicks a link to close it. Otherwise, you'd have to set up polling to check for the existence of the child, and refresh if it doesn't exist. Please Mark As Answer posts that helped you."If we learn from our mistakes, I should be brilliant by now." Thanks, this gives me part of the answer...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

Web resources about - How to databind control in one web page from another web page - asp.net.web-forms

TAG Heuer: Luxury watches for men and women since 1860
Find the TAG Heuer store closest to your home: TAG Heuer, a much referenced brand in luxury watches and other prestige products - chronographs, ...

dotnet HighCharts inside UpdatePanel
Read my article about the HighCharts.net databind? A frequently question regards the possibility to get functioning a dotnet.HighCharts chart ...

Jackson Data Binding Message Serialization
... languages we’re immediately concerned with, and more or less straightforward. For my Java-based server I am using Jackson and Jackson-databind ...

Boost ASP.NET performance with deferred content loading
A comprehensive example of how to improve the perceived speed of your pages, by implementing user controls to encapsulate secondary content and ...

Maven Repository: Open Source
Categories - Popular - Contact Us Artifacts/Year Popular Categories Aspect Oriented Actor Frameworks Application Metrics Build Tools Bytecode ...

RSSBus ADO.NET Provider for Google - Overview
The Google Data Provider gives developers the power to easily connect .NET applications to popular Google Services including GMail, Google Docs, ...

CodeSOD: Today's Article is Brought to You by the Letters "WTF"
... = "Z" dr.Item("Alphabets") = "Z" tempTable.Rows.Add(dr) End Select Next Me.rptAlphabets.DataSource = tempTable Me.rptAlphabets.DataBind() End ...

HOW TO: Use SQLite in C# Metro style app
The web site and blog of Tim Heuer, Program Manager for Microsoft XAML. A resource to learn how to develop software with XAML technologies. This ...

SQLite WinRT wrapper for Windows Phone
... named cities.db (in the app’s local folder) and then adding the contents of the Cities table to an ObservableCollection . You can then databind ...

Listbox, Why Art Thou Blanking?
... the user moves downwards we balance the buffers by transferring the excess buffer from the top buffer (red) to the bottom buffer and re-databind ...

Resources last updated: 12/6/2015 11:42:06 PM