Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i click on the image button it should redirect me to another page.
but iam unable to.
the code i have written is
<asp:ImageButton runat="server" ID="imgBtn" onclick="imgBtn_Click"/>

C#
protected void imgBtn_Click(object sender, ImageClickEventArgs e)
      {
          Response.Redirect("~/resource.aspx");
      }

can any one help me
Posted

Strange. Is it raising any error sort of thing or remaining in the same page
 
Share this answer
 
Comments
srujanac# 30-Aug-10 1:48am    
iam getting an error
System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true"> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
demouser743 30-Aug-10 1:54am    
Have u written some sort of validations or anything or simply you are transferring page on image click with out any sort of code
srujanac# 30-Aug-10 1:58am    
no, i just need to go to other page when i click on the image button
demouser743 30-Aug-10 2:12am    
Is there any other code you have written on the page or some sort of thing on the page load of the second page
srujanac# 30-Aug-10 2:35am    
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.DataItem != null)
{
ImageButton imgBtn = (ImageButton)e.Item.FindControl("imgBtn");
//
string path = (((System.Data.DataRowView)(e.Item.DataItem)).Row.ItemArray[0].ToString());
int ind = path.LastIndexOf(".");
string fileType = path.Substring(ind + 1).ToString();
//string str = Server.MapPath("~/images/icon_pdf.png");
if (fileType == "pdf")
{
imgBtn.ImageUrl = "~/images/icon_pdf.png";
}

else
{
imgBtn.ImageUrl = "~/images/icon_word.png";
}

}

}

and
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("~/resource.aspx");
}

and in the page load of the other page i have bounded a datalist to a datasource
I assume that, despite your not telling us so, this is an ASP.NET website ? have you set a break point to see if your event fires ? I see no reason for this code to not work. I don't recognise ImageClickEventArgs, but I assume this is the right event, IDE generated.
 
Share this answer
 
Comments
srujanac# 30-Aug-10 1:50am    
the event itself is nit firing but idont know the reason

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