Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Image button postbackurl is not working its not directing to the destination page and imagebutton its not inside any control like gridview or Datalist its seperate and this is my code

ASP.NET
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/icon-continue-shopping-4-150x49.jpg" PostBackUrl='<%#"Order_Details.aspx?pid="+Eval("ProductID") %>'/>

And code in the Order_Details.aspx

 protected void Page_Load(object sender, EventArgs e)
    {

        BindGridData();
        if (!IsPostBack)
        {
        }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {

    }
    private void BindGridData()
    {
        try
        {
            con.Open();
            int pitemid = Convert.ToInt32(Request.QueryString["pid"].ToString());
            {
                string sql = "select * from rsa_ProductItemTable where ProductID=" + pitemid;
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }

        catch (Exception ex)
        {
        }
        finally
        {
            con.Close();
        }
    }
}

Please help me to solve this. Thanks in Advance!!
Posted
Updated 3-Mar-15 21:19pm
v2

1 solution

Although you have clearly mentioned that the image button is not inside any control like gridview or datalist, still I'll ask, are you sure?
ASP.NET
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/icon-continue-shopping-4-150x49.jpg" PostBackUrl="<%#"Order_Details.aspx?pid="+Eval("ProductID") %>" />

What Eval("ProductID") should evaluate to?

Just for a test you can try replacing the above snippet with
ASP.NET
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/icon-continue-shopping-4-150x49.jpg" PostBackUrl="Order_Details.aspx?pid=1" />

It should redirect to Order_Details.aspx with pid=1 and the logic you have written will be executed.

I am sure, you want this image button to redirect somewhere else.
You can also use OnClick event if want to do it other way.

In case, your problem is not resolved, please let me know :)
 
Share this answer
 
v2
Comments
What an answer man. :) Cool.

I did some edits for those HTMLs.
Suvendu Shekhar Giri 4-Mar-15 3:40am    
Thanks :)
kwelpooh 4-Mar-15 3:39am    
THANKS FOR THE REPLY. Yes its not working yes i want to redirect to another page if i use the Onclick event how to pass the query string and request that in another page can u please help me with this?
Suvendu Shekhar Giri 4-Mar-15 3:42am    
What you want as querystring and from where you get that value?
kwelpooh 4-Mar-15 3:45am    
ProductId value from Table (rsa_ProductItemTable)

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