Click here to Skip to main content
15,885,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my cs file is....

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text;
using System.Drawing;



public partial class approvedreports : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["hospitalConnectionString"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string str = "select s_no, Rejected, first_name, second_name, bill_number, Labname, testname, approval_date from testrates where Rejected = 'R'";
            gvDetails11.DataSource = getdata(str);
            gvDetails11.DataBind();
        }
    }



     private DataTable getdata(string str)
    {
        SqlCommand cmd = new SqlCommand(str, con);
        DataTable dt = new DataTable();

        SqlDataAdapter adp = new SqlDataAdapter();
        adp.SelectCommand = cmd;
        adp.Fill(dt);
        con.Close();
        return dt;
    }

   protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string str1 = "select s_no, Rejected, first_name, second_name, bill_number, Labname, testname, approval_date from testrates where Rejected = 'R'";
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        using (StringWriter sw = new StringWriter())
        {
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            //To Export all pages
             gvDetails11.AllowPaging = false;
             this.getdata(str1);

             gvDetails11.HeaderRow.BackColor = System.Drawing.Color.White;
             foreach (TableCell cell in gvDetails11.HeaderRow.Cells)
            {
                cell.BackColor = gvDetails11.HeaderStyle.BackColor;
            }
             foreach (GridViewRow row in gvDetails11.Rows)
            {
                row.BackColor = Color.White;
                foreach (TableCell cell in row.Cells)
                {
                    if (row.RowIndex % 2 == 0)
                    {
                        cell.BackColor = gvDetails11.AlternatingRowStyle.BackColor;
                    }
                    else
                    {
                        cell.BackColor = gvDetails11.RowStyle.BackColor;
                    }
                    cell.CssClass = "textmode";
                }
            }

             gvDetails11.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
        
      }

    }

my aspx file is..
XML
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="approvedreports.aspx.cs" Inherits="approvedreports" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .Gridview
        {}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</br>
</br>
</br>
</br>
</br>
</br>
<form id="fm" runat="server">
 <asp:Panel ID="Panel1" runat="server">
<asp:GridView ID="gvDetails11" runat ="server"
AutoGenerateColumns="False" CssClass="Gridview" HeaderStyle-BackColor="#61A6F8"
ShowFooter="True" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White"
        HorizontalAlign="Center"  DataKeyNames="bill_number" Width="998px"
       >




        <Columns>
            <asp:BoundField DataField="s_no" HeaderText="Serial Number"></asp:BoundField>
            <asp:BoundField DataField="first_name" HeaderText="First Name"></asp:BoundField>
            <asp:BoundField DataField="second_name" HeaderText="Second Name">
            </asp:BoundField>
            <asp:BoundField DataField="bill_number" HeaderText="Bill Number">
            </asp:BoundField>
            <asp:BoundField DataField="Labname" HeaderText="Labname"></asp:BoundField>
            <asp:BoundField DataField="testname" HeaderText="Test Name"></asp:BoundField>
            <asp:BoundField DataField="approval_date" HeaderText="Date Of Apporval">
            </asp:BoundField>
        </Columns>
<HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White"></HeaderStyle>




        </asp:GridView>


        </asp:Panel>
        <table align = "center">
        <tr>
        <td>
        <asp:ImageButton ID="ImageButton2" runat="server" Height="52px"
                ImageUrl="~/Images/downlaod.jpg" onclick="ImageButton1_Click" Width="75px"></asp:ImageButton>
        </td>
        </tr>
        </table>
        </form>



</asp:Content>

and my master page is ..

ASP.NET
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
    
    <style type="text/css">
        .style1
        {
            width: 174px;
            text-align: left;
            background-color: #F5F5F5;
        }
        .style2
        {
            width: 100%;
        }
         .sortable:hover {
    cursor: pointer;
    cursor: hand;
}
        .style4
        {
            font-family: "Gill Sans MT Condensed";
            font-size: x-large;
            color: #663300;
        }
        .style5
        {
            width: 477px;
            height:98px;
        }
        .style6
        {
            height: 98px;
        }
        .style7
        {
            color: #CC3300;
        }
        .style8
        {
            color: #CC9900;
        }
        .style9
        {
            font-family: "Gill Sans MT Condensed";
            font-size: xx-large;
            color: #663300;
        }
        .style10
        {
            width: 480px;
            height: 100px;
        }
        </style>
</head>
<body>
    
    <div>
        <table class="style2" style="height: 98px; background-color: #CCCCCC">
            <tr>
                <td style="text-align: left; background-image: removed('/WebSite14/Images/Stethoscope-Doctor1.jpg');">
                    class="style5">
   
                    <img alt="" class="style10" src="Images/Stethoscope-Doctor1.jpg" /></td>
                <td style="text-align: center; " class="style6">
         
                    <span class="style9"><span class="style7">Medical</span> <span class="style8">Bill</span>
                    <span class="style7">Reimbursement</span></span><span class="style4">
                    <br />
                    </span>
                    <asp:Label 
            ID="Label4" runat="server" Text="Portal" CssClass="style4">
                    </td>
                <td style="text-align: right;" class="style6">
        <asp:Label ID="Label5" runat="server" style="font-size: x-large; font-weight: 700; font-family: 'Monotype Corsiva'; color: #FFFFFF;"
                        Text="Welcome">
  
        <asp:ImageButton ID="ImageButton2" runat="server"  src="Images/logout.png"  
            Height="22px" Width="80px" onclick="ImageButton2_Click" />
 
                </td>
            </tr>
            </table>
 
      
        <table width="100%">
            style="height: 436px"><tr><td class="style1" valign="top">
                <br />
                <br />
                <br />
                <br />
                <br />
                <asp:Button ID="ED" runat="server" BorderStyle="None" Text="Employee Details"  
                    class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
                    Width="150px" onclick="ED_Click" />
                <br />
                <br />
                <asp:Button ID="OutDoor" runat="server" BorderStyle="None" Text="OutDoor Details"  
                    class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
                    Width="150px" onclick="OutDoor_Click" />
                <br />
                <br />
                <asp:Button ID="Bills" runat="server" BorderStyle="None" Text="Upload Bills"  
                    class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
                    Width="150px" onclick="Bills_Click" />
                <br />
                <br />
                <asp:Button ID="Test" runat="server" BorderStyle="None" Text="Test Details"  
                    class="sortable" style="font-family: Algerian; background:rgba(4,41,64,0.3);"
                    Width="150px" onclick="Test_Click" />  
                <br />
                <br />
                <asp:Button ID="Download" runat="server" BorderStyle="None" Text="Download Form"  
                    class="sortable" style="font-family: Algerian; background: rgba(4,41,64,0.3);"
                    Width="150px" onclick="Download_Click" Height="21px" />  
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />


                <br />
                <br />


                <br />
                <br />

                <br />
                <br />

<br />
                <br />
                <br />


                <br />
                <br />
                

                <br />


                </td><td>
                      <asp:Panel ID="panel1" runat="server" Height="1000" ScrollBars="Auto">
                <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        
        </td></tr></table>
    </div>
   
</body>
</html>



kindly help me guys..
Posted
Updated 20-Aug-15 19:15pm
v2

VB
<asp:ImageButton ID="ImageButton2" runat="server"  src="Images/logout.png"
          Height="22px" Width="80px" onclick="ImageButton2_Click" />


In asp u have to use ImageUrl instead of src

VB
<asp:ImageButton ID="ImageButton2" runat="server"  ImageUrl="Images/logout.png"
          Height="22px" Width="80px" onclick="ImageButton2_Click" />
 
Share this answer
 
v2
You are getting error due to following reasons:

1. Your master doesn't contain any form tag. And you are using server side control without any form runat="server".

2. If it is really necessary to use image button in master then you can add form tag in master page with run at server. Add image button inside it. Remove form tag in child pages other otherwise it will throw you error that page cannot contain multiple form tag.
 
Share this answer
 
Instead of adding form tags in aspx page add it in master page only.
Add master page all the body content inside form tag with runat server. And provide closing tags for labels in master page file.
In the master page file you have written like
asp:ContentPlaceHolder with id="head" and it needs to be closed before close of the head tag.
In the last added lines like
asp:Panel ID="panel1"
iside
asp:ContentPlaceHolder id="ContentPlaceHolder1"
provide closing tags respectively.
 
Share this answer
 

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