Error : panel1 does not exist in correct context
<p>How do I resolve this error.</p>

<p>my code is </p>

<pre><code>&lt;asp:GridView ID="gridView" runat="server" Style="position: relative; left: 299px; top: 69px;" PageSize="5" OnRowCommand="gridView_OnRowCommand" AllowPaging="True" OnSelectedIndexChanged="gridView_SelectedIndexChan ged1" &gt;

&lt;PagerTemplate&gt;
&lt;% if (gridView.PageIndex &gt; 0) 
{ %&gt;
&lt;asp:ImageButton ID="imgBtnPrevious" runat="server" Style="vertical-align: middle;" ImageUrl="pre.jpg" OnClick="click1" 
CommandArgument="Prev" CommandName="Page" /&gt; 

&lt;% } %&gt; 

&lt;%=(gridView.PageIndex * 5) + 1%&gt; &lt;%=(gridView.PageIndex * 5) + gridView.Rows.Count%&gt; 
&lt;% if (gridView.PageIndex != (gridView.PageCount - 1)) 
{ %&gt; 



&lt;asp:ImageButton ID="imgBtnNext" runat="server" Style="vertical-align: middle;" ImageUrl="next.jpg" OnClick="click" CommandArgument="Next" CommandName="Page" /&gt; 
&lt;% } %&gt; 

&lt;%--&lt;asp:ImageButton ID="imgBtnNext" runat="server"
Style="vertical-align: middle;" ImageUrl="next.jpg" 
CommandArgument='&lt;%# Eval("Next")%&gt;' OnClick="click" CommandName="Page" /&gt;--%&gt;
&lt;/PagerTemplate&gt;
&lt;/asp:GridView&gt;
&lt;/aspanel&gt;
&lt;%--&lt;%=(gridView.PageIndex * 5) + 1%&gt; &lt;%=(gridView.PageIndex * 5) + gridView.Rows.Count%&gt; --%&gt; 
&lt;% if (gridView.PageIndex != (gridView.PageCount - 1)) 
{ %&gt; 



&lt;asp:ImageButton ID="imgBtnNext" runat="server" Style="vertical-align: middle;" ImageUrl="next.jpg" OnClick="click" CommandArgument="Next" CommandName="Page" /&gt; 
&lt;% } %&gt; 

&lt;%--&lt;asp:ImageButton ID="imgBtnNext" runat="server"
Style="vertical-align: middle;" ImageUrl="next.jpg" 
CommandArgument='&lt;%# Eval("Next")%&gt;' OnClick="click" CommandName="Page" /&gt;--%&gt;
&lt;/PagerTemplate&gt;
&lt;/asp:GridView&gt;
</code></pre>

<p>and code behind is </p>

<pre><code>public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        SqlDataAdapter adapPaging = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
        adapPaging.Fill(ds);

        gridView.DataSource = ds;
        gridView.DataBind();
    }

    public void click1(object send, ImageClickEventArgs e)
    {
        GridViewPageEventArgs obj = new GridViewPageEventArgs(gridView.PageIndex - 1);

        gridView.PageIndex = obj.NewPageIndex;

        LinkButton exmp = new LinkButton();
        exmp.Text = "exmp";
        Panel1.Controls.Add(exmp);
    }

    public void click(object send, ImageClickEventArgs e)
    {
        GridViewPageEventArgs obj = new GridViewPageEventArgs(gridView.PageIndex+1);

        gridView.PageIndex = obj.NewPageIndex;
    }
}
</code></pre>
