Link to home
Start Free TrialLog in
Avatar of dmontgom
dmontgom

asked on

Using Codebehind to communicate between frames

Hello,

Lets say I have a Framset that has a top, framtop.aspx and a botton, frame bottom.aspx.  In frame top, I have a button that executes a query and I want to put into frame bottom the results of that query in a data grid.  I want to do all of this in the framtop code behind.

LEts say my DatGrid is called DG4

How do I do that? What is all of the code nescessary that I have to put in my framtop to communicate with my fram bottom.


Bonus points of 50 if you can tell me how if my frambottom is initially 0% that when the button clicks the bottom fram goes to 30%.

Thanks
Avatar of Edward Diaz
Edward Diaz
Flag of United States of America image

You want to use the server.transfer method in asp.net to send the info to other pages.

An example can be found at:

https://www.experts-exchange.com/questions/20859069/submitting-form-to-new-window.html?query=asp.net+server.transfer+method&clearTAFilter=true

Hope I helped!
Kittrick
I'm going to take a stab at the 0 to 30% problem, and say it could be one of two things:

1) Your frame that contains the button is set to size to whatever is left over which happens to be 30%

example:

<html>

<frameset cols="50%,20%,*">

  <frame src="tryhtml_frame_a.htm">
  <frame src="tryhtml_frame_b.htm">
  <frame src="tryhtml_frame_c.htm">

</frameset>

</html>

the * denotes that it will resize to whatever is left over as a remainder...which in this case, would be 30%


2) The frame is actually sized at 30% of the screen (substitute the * above with a literal 30%).

Those are the only two things I could think of.

Kittrick


Avatar of dmontgom
dmontgom

ASKER

Thanks.  I am looking for exact code.  THis is what i tried with the link but it does on work

In the top portion of the frame when I click the submit button I have

        Dim objConn As New OleDbConnection("Provider=""xxx"";password=xxx;User ID=xxx;Data Source=xxx")
        Dim objCmd As New OleDbDataAdapter("Select * from eval_ad_final", objConn)
        Dim ds As DataSet = New DataSet
        objCmd.Fill(ds, "eval_ad_final")
        objConn.Close()

        Server.Transfer("outcome_results.aspx", True)


In the bottom portion of my frame I have

        Dim ds
        Dim temp

        Response.Redirect("outcome_results.aspx?ds=ds")
        temp = Request.QueryString("ds")
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()


My question is 1) where do I put the code in the bottom portion of the frame.  I it on page load?  What is the subroutine it should be in that when the button is executed in the top portion of the frame, the data source created in the top portion of the frame is then automatically bound to the DataGrid in the bottom portion of the frame.  Also, the page did redirect but it redirected in the top portion of the frame.

What should the exact code be?

Thanks





Actually this is my code in the top frame

Response.Redirect("outcome_results.aspx?myvariable=ds")

To grab the data source (ds) in the botton frame I use

 DataGrid1.DataSource = Request.QueryString("myvariable")

It does not want to work.  I just want the bottom frame to load the data generated in the first frame.  However, when I use Response.Redirect("outcome_results.aspx?myvariable=ds") the top frame is replaced by the page that I want to be the bottom frame

 
I think I know what your problem is. I did the same thing you want to do, EXCEPT I had two completely seperate pages....one to send the data and one to catch it from the first page. When you are trying to get your data, it is updating the same frame because it is the same page. Create a second aspx page and name it whatever you want.  Here's your code to illustrate:


'initiating the OleDB data connection

Dim objConn As New OleDbConnection("Provider=""xxx"";password=xxx;User ID=xxx;Data Source=xxx")
        Dim objCmd As New OleDbDataAdapter("Select * from eval_ad_final", objConn)
        Dim ds As DataSet = New DataSet
        objCmd.Fill(ds, "eval_ad_final")
        objConn.Close()


'transferring data to the new page and saving state of current page in transit
        Server.Transfer("mynewpage.aspx", True)


'mynewpage is called in the bottom frame and receives the data

        Dim ds
        Dim temp

        Request.Form("ds")
        temp = Request.QueryString("ds")
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()



Here's an interesting excerpt from an article I found:

-----------------------------------------------------------------------------------------
Server.Transfer Vs. Response.Redirect
http://www.developer.com/net/asp/print.php/3299641
The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at http://support.microsoft.com/default.aspx?id=kb;en-us;Q316920.

--------------------------------------------------------------------------------------

Hopefully this works, but I think honestly what you are trying to achieve is more difficult than it should be.

Just curious, is there a specific reason that you want to do this in frames and not in <asp:panel> 's?? Panels seperate things on a page without having to transfer things between pages. You could put your datagrid in a seperate panel than your query fields and even toggle visibility.  

I will write back tomorrow with an easier specific solution you may be interested in.

Kittrick
Hi

Thanks for the help.  Will try and be more specific

In my top frame, I have the following that is the last line of code in a button_onclick command
Server.Transfer("outcome_results.aspx", True)  


In the page load of the bottom frame on the page load event in the vb code behind I have

        Dim ds
        Dim temp

        Request.Form("ds")
        temp = Request.QueryString("ds")
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()


In the Request.form("ds") line the ds has the squigly line under it like the vb code does not know what ds is?  is the Request.Form("ds") line correct?  BTW, I am importing on the second frame the code from the first page by using <%@ Reference Page="outcome.aspx" %> on the second page.

Also, yeah, this is a true pain. I really can't believe it is this difficult. Changing little stuff gets the form to pop but in a full page window.  I get know error but the again, i still do not get the data.

As far as what I want to do?  THis is the issue.  I have three grid controls side by side and the user checks options in each of the three grids and clicks a button.  THe button the executes a query and then returns the data to DataGrid.  TO make it look nice, I wanted the data grid to return to a bottom portion of the frame so the user can still see the options used above because users can change the above options on the fly and see updated changes below.  THe other issue as that the number of records for the three above data bound grids above can change thus making the number of rows variable.   I do not want to allow paging on the data grid.

If I can't get the frames to communicate properly then I will try grids.  Any examples on how to add e.g. two grids to a panel and then have a user buttone to switch between grids using a button or check box?

Thanks for the help





ASKER CERTIFIED SOLUTION
Avatar of Edward Diaz
Edward Diaz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My last question I hope

Got the datagrid to work dynamically.

Rather than reloading the query on every postback, is it possible to create a datatable that lasts throught the sesssion without having to recreate the table?  This posback is really starting to work against me becuase now every time I postback, I loose the checkboxes in the data drid that people check and I have know if keeping track of it.  If I can fill a table once, and call that table between sessions, then I am happy.

But, it seems like I loose the table as well.


Dim DataGridpl As New DataTable("Placement")

I want to fill DataGridpl just once and the have it persist through postback.  Possible?  It seems not

Thanks
Panels worked great.  Lovel them

Ignore the last comment I made.  This is the very last thing I have to do.

I hae checkboxes in the grids in my panel.  When I switch between grids I loose what the user checked.  I switch between grids in a panel using a radio list box.  What I want to do is write to a database table what the user checked before the information on what the user checked is lost.  What event fires when a change to the second grid using the radio control button is selected but I can still capture the information in datagrid 1.

I tried radiobuttonlist_onselectionchanged but did not work

ANy ideas?
I now hate the data grid control.  WOrthless whwn dealing with checkboxes and postbacks.  I can't get the damn checkboxes back.  I get everything else back but that is just because I rebind everytime.  No real solution there.

Thanks for the help
Sorry for writing back so late. Yes, datagrids are a serious pain because the .NET framework assumes a lot of control and gives you very little to customize. For what you want to do, you might want to look into the <datalist> with a <repeater>, but it requires you to explicitly write each and every behaviour that is built into a datagrid.  You can, however, mix JavaScript and Asp.net together to get pop-up windows or something that may not be affected by the postback. This is the biggest problem with ASP.NET in that EVERY OBJECT has to be tied to the server on postback in order for it to work at all.


Kittrick
Total Pain but I got everything to work now by using multipanels.  Nesting panels in panels.  Just a pain to program around keeping track of them and what should be visable or not.

Thanks for the input on panels, big help