Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi There,

I am able to record the data on the next page, that is working. The only thing I am trying to figure out now is how to display the data within the aspx contentplaceholder1 of my page. I am using a masterpage and the data is being displayed outside the MasterPage and contentplaceholder of my next page. I do not mind the format shown.

The code behind the page, SearchGen.aspx.cs is as follows:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
 
public partial class Members_SearchGen : System.Web.UI.Page
{
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
     protected void Button2_Click(object sender, EventArgs e)
    {
        if (GridView.SelectedRow != null)
        {
            GridViewRow selectedRow = GridView.SelectedRow;
 
            Session["FamilyName"] = selectedRow.Cells[1].Text;
            Session["FirstName"] = selectedRow.Cells[2].Text;
            Session["MiddleName1"] = selectedRow.Cells[3].Text;
            Session["MiddleName2"] = selectedRow.Cells[4].Text;
            Session["MiddleName3"] = selectedRow.Cells[5].Text;
            Session["Gender"] = selectedRow.Cells[6].Text;
            Session["DOB"] = selectedRow.Cells[7].Text;
            Session["COOB"] = selectedRow.Cells[8].Text;
            Session["SOB"] = selectedRow.Cells[9].Text;
            Session["COB"] = selectedRow.Cells[10].Text;
            Session["GenType"] = selectedRow.Cells[11].Text;
            Session["GenRank"] = selectedRow.Cells[12].Text;
            Session["GenTitles"] = selectedRow.Cells[13].Text;
            Session["GenTitles1"] = selectedRow.Cells[14].Text;
            Session["GenTitles2"] = selectedRow.Cells[15].Text;
            Session["DOD"] = selectedRow.Cells[16].Text;
            Session["COOD"] = selectedRow.Cells[17].Text;
            Session["SOD"] = selectedRow.Cells[18].Text;
            Session["COD"] = selectedRow.Cells[19].Text;
             
             
            Server.Transfer("SearchResults.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
        }
    }
}



The code behind the next page, SearchResults.aspx.cs is as follows:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Members_SearchResults : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (this.Page.PreviousPage != null)
     {
         
 
         GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
         //GridViewRow selectedRow = GridView1.SelectedRow;
         Response.Write("Family: " + Session["FamilyName"].ToString() + "<br />");
         Response.Write("First: " + Session["FirstName"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName1"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName2"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName3"].ToString() + "<br />");
         Response.Write("Gender: " + Session["Gender"].ToString() + "<br />");
         Response.Write("Birthday: " + Session["DOB"].ToString() + "<br />");
         Response.Write("Country: " + Session["COOB"].ToString() + "<br />");
         Response.Write("State: " + Session["SOB"].ToString() + "<br />");
         Response.Write("City: " + Session["COB"].ToString() + "<br />");
         Response.Write("Type: " + Session["GenType"].ToString() + "<br />");
         Response.Write("Rank: " + Session["GenRank"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles1"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles2"].ToString() + "<br />");
         Response.Write("Death: " + Session["DOD"].ToString() + "<br />");
         Response.Write("Country: " + Session["COOD"].ToString() + "<br />");
         Response.Write("State: " + Session["SOD"].ToString() + "<br />");
         Response.Write("City: " + Session["COD"].ToString() + "<br />");
    }
    }
}


Here is what shows up on my result page, SearchResults.aspx, see below:

Family: Whalen
First: Anthony
Middle: Stewart
Middle:
Middle:
Gender: Male
Birthday: 01/08/1962/AD
Country: Canada
State: Nova Scotia
City: Halifax
Type:
Rank:
Titles:
Titles:
Titles:
Death:
Country:
State:
City:

As can been showned above the results are being shown outside the masterpage, I need this to show up with the contentplaceholder1 of the foloowing masterpage. I think it is something small that I am missing, I need help with this. Can anyone help, it would be much appreciated and look forward to your feed back.

Thanks

ASW
Posted

1 solution

This happening because you are using Response.write which writes values at the start of HTTP response.

In this case you can follow below steps.

1. Declare protected string variable at class level in your SearchResults.aspx.cs like below

protected string OutPutString ="";


2. Instead of using Response.write, append your string to OutPutString like below
OutPutString += "Family: " + Session["FamilyName"].ToString() + "<br />";
 OutPutString +="First: " + Session["FirstName"].ToString() + "<br />";


3. In your SearchResults.aspx display this string where you want to using ASP.NET inline expressions

<%=OutPutString%>


Hope this will help.

One more thing if you are performance concerned then you can use StringBuilder class for appending strings.
 
Share this answer
 
v4
Comments
Member 9142936 26-Oct-13 15:00pm    
How would I configure this into my existing code, do I add this as part of my existing code under "protected void Page_Load(object sender, EventArgs e)", or do I delete my existing and build the "outputstring".
Mahesh Bailwal 26-Oct-13 15:36pm    
delete your existing code where you are using response.write and use outputstring.
Member 9142936 27-Oct-13 12:10pm    
Hi Mahesh,

Thank you for your quick response, I have written the code for the response.write for the SearchResults page. I got an error in the code, the error was as follows:

"Server Error in '/' Application."


Quote:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1043: { or ; expected

Source Error:


Line 14: {
Line 15:
Line 16: get (this.Page.PreviousPage != null)
Line 17: {
Line 18:


Source File: c:\Genealogy\Members\SearchResults.aspx.cs Line: 16



Below is a copy of my code for SearchResults.aspx.cs, which as follows:


<blockquote class="FQ"><div class="FQA">Quote:</div>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Members_SearchResults : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public String OutPutString
{

get (this.Page.PreviousPage != null)
{

protected String OutPutString ="";

GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
//GridViewRow selectedRow = GridView1.SelectedRow;
OutPutString += "Family: " + Session["FamilyName"].ToString() + "<br />";
OutPutString += "First: " + Session["FirstName"].ToString() + "<br />";
OutPutString += "Middle: " + Session["MiddleName1"].ToString() + "<br />";
OutPutString += "Middle: " + Session["MiddleName2"].ToString() + "<br />";
OutPutString += "Middle: " + Session["MiddleName3"].ToString() + "<br />";
OutPutString += "Gender: " + Session["Gender"].ToString() + "<br />";
OutPutString += "Birthday: " + Session["DOB"].ToString() + "<br />";
OutPutString += "Country: " + Session["COOB"].ToString() + "<br />";
OutPutString += "State: " + Session["SOB"].ToString() + "<br />";
OutPutString += "City: " + Session["COB"].ToString() + "<br />";
OutPutString += "Type: " + Session["GenType"].ToString() + "<br />";
OutPutString += "Rank: " + Session["GenRank"].ToString() + "<br />";
OutPutString += "Titles: " + Session["GenTitles"].ToString() + "<br />";
OutPutString += "Titles: " + Session["GenTitles1"].ToString() + "<br />";
OutPutString += "Titles: " + Session["GenTitles2"].ToString() + "<br />";
OutPutString += "Death: " + Session["DOD"].ToString() + "<br />";
OutPutString += "Country: " + Session["COOD"].ToString() + "<br />";
OutPutString += "State: " + Session["SOD"].ToString() + "<br />";
OutPutString += "Titles: " + Session["COD"].ToString() + "<br />";
}
}
}</blockquote>
Member 9142936 27-Oct-13 12:23pm    
Continue:

The code for SearchResults.aspx is as follows:

<%@ Page Title="" Language="C#" MasterPageFile="~/Members/Main.master" AutoEventWireup="true" CodeFile="SearchResults.aspx.cs" Inherits="Members_SearchResults" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<link href="Styles/Content1.css" rel="stylesheet" />
<div id="content">
<br /><%=OutPutString%>
<br />
<br />
<br />
<br />
<br />
</div>
<div id="ad" class="style55" style="font-family: Arial, Helvetica, sans-serif">Please place your ad here....</div>


Do you have any ideas of how to correct the error, I am sure it is something small that I am missing?

Thanks again for your help and look forward to hearing from you in the near future.

Thanks


ASW
Mahesh Bailwal 27-Oct-13 13:13pm    
Below is what I was suggesting, its not properly formatted but what I was suggesting is that you need create protected string not property. Hope below code help.


public partial class Members_SearchResults : System.Web.UI.Page {
protected string OutPutString ="";
protected void Page_Load(object sender, EventArgs e) {

if (this.Page.PreviousPage != null)
{

GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1"); //GridViewRow selectedRow = GridView1.SelectedRow; OutPutString += "Family: " + Session["FamilyName"].ToString() + "<br />"; OutPutString += "First: " + Session["FirstName"].ToString() + "<br />"; OutPutString += "Middle: " + Session["MiddleName1"].ToString() + "<br />"; OutPutString += "Middle: " + Session["MiddleName2"].ToString() + "<br />"; OutPutString += "Middle: " + Session["MiddleName3"].ToString() + "<br />"; OutPutString += "Gender: " + Session["Gender"].ToString() + "<br />"; OutPutString += "Birthday: " + Session["DOB"].ToString() + "<br />"; OutPutString += "Country: " + Session["COOB"].ToString() + "<br />"; OutPutString += "State: " + Session["SOB"].ToString() + "<br />"; OutPutString += "City: " + Session["COB"].ToString() + "<br />"; OutPutString += "Type: " + Session["GenType"].ToString() + "<br />"; OutPutString += "Rank: " + Session["GenRank"].ToString() + "<br />"; OutPutString += "Titles: " + Session["GenTitles"].ToString() + "<br />"; OutPutString += "Titles: " + Session["GenTitles1"].ToString() + "<br />"; OutPutString += "Titles: " + Session["GenTitles2"].ToString() + "<br />"; OutPutString += "Death: " + Session["DOD"].ToString() + "<br />"; OutPutString += "Country: " + Session["COOD"].ToString() + "<br />"; OutPutString += "State: " + Session["SOD"].ToString() + "<br />"; OutPutString += "Titles: " + Session["COD"].ToString() + "<br />"; }
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900