It is not possible for me to edit your code as I cannot run it. So you will have to do it yourself. But I can help you pass TextBox content to the other page
1. Create a new Page Report.aspx, this page we will open in new window and will print the report
2. And on the button click remove the code you have now and put the following line
ClientScript.RegisterStartupScript(this.GetType(), "alert", string.Format("window.open('Report.aspx?q={0}')", TextBox1.Text), true);
The above line will open Report.aspx in new window and also pass TextBox Text to that page using QueryString
3. In Report.aspx paste the following code in Page_Load event
string query;
try
{
string q = Request.QueryString["q"];
con.Open();
query = "select * from Transactions where idcount='" + q + "'";
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ReportDocument MedicalReport = new ReportDocument();
MedicalReport.Load(Server.MapPath("~/CrystalReport4.rpt"));
MedicalReport.SetDataSource(dt);
query = "select * from Transactions where idcount='" + TextBox1.Text + "'";
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
dt1.Clear();
da.Fill(dt1);
MedicalReport.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport");
CrystalReportViewer1.ReportSource = MedicalReport;
CrystalReportViewer1.ReportSource = MedicalReport;
CrystalReportViewer1.DataBind();
}
}
catch
{
Message("Please enter Text", this);
}
finally
{
con.Close();
}