Get information from one page and show it on another page

im running a shopping cart site i want to show full details of a product contained in a div section. on another page. I have a div that contains information. The goal is to get information on a new page when a user clicks on an image of any product.

   Error: 
           Control 'MainContent_ImageButton1' of type 'ImageButton' must be placed inside a form tag with runat=server.
    HTML:
      <div id="physics" runat="server">
        <h3>High School Physics</h3>
      <%--  <a href="ShowLarge.aspx"> <img src="images/Book.jpg" />  </a>--%>
        <asp:ImageButton ID="ImageButton1" 
                src="images/Book.jpg" runat="server" onclick="ImageButton1_Click"  />
        <p> Book Description Goes Here
        <br />
         <asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
         <br />
         <asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>

         <asp:Button ID="Button1" runat="server" Text="Add" />
        </p>

    </div>

    Code :
     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            StringWriter sw = new StringWriter();
        HtmlTextWriter w = new HtmlTextWriter(sw);

        physics.RenderControl(w);
        Session["mySessionVar"]  = sw.GetStringBuilder().ToString();

            Response.Redirect("ShowLarge.aspx", true);

        }

    HTML: where i want to show this info 

    <div id="ShowInLargeView" runat="server">
    </div>

    Code: 

     protected void Page_Load(object sender, EventArgs e)
        {
            ShowInLargeView.InnerHtml = (String)Session["mySessionVar"];
        }

      

I want to show full details of a Div on another page. I am getting an error. this script is about shopping cart i need help please help.

+3


source to share


1 answer


The error you are getting is because you are trying to add an event handler

   protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

      

To add an event handler to an element on your page, it must be encapsulated in a "form" with a runat = "server" attribute. this will cause the clickButton event to end up in your code.



so your aspx will become something like:

<form runat="server">
      <div id="physics" runat="server">
        <h3>High School Physics</h3>
      <%--  <a href="ShowLarge.aspx"> <img src="images/Book.jpg" />  </a>--%>
        <asp:ImageButton ID="ImageButton1" 
                src="images/Book.jpg" runat="server" onclick="ImageButton1_Click"  />
        <p> Book Description Goes Here
        <br />
         <asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
         <br />
         <asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>

         <asp:Button ID="Button1" runat="server" Text="Add" />
        </p>

    </div>
</form>

      

In general, this is enough to encapsulate your entire page in a form tag so that all events will be passed to your code.

0


source







All Articles