2

I have an asp.net image button that basically displays an image of a product based on user selections, and sets a link to an external site accordingly. When I click the image button in IE, it crashes the site, but it seems to work fine in Chrome. As an example:

if (TotalWattage > 1 && TotalWattage < 275) //depending on wattage calculation, shows PSU recommendation
    {
        imgbtnPSURecommend.ImageUrl = "~/Images/PSU Tool Images/CM-300.jpg";
        lblPSURecommend.Text = "300w COOLMAX CM-300";
        imgbtnPSURecommend.PostBackUrl = "http://www.newegg.com";
    }

If I launch the site and click the image, it crashes back to Visual Studio and says "JavaScript critical error at line 32, column 17." The error just says:

function onclick(event)
{
javascript:void()
}

If I change the url to www.google.com instead, Google loads with "Your client issued a request that was too large. That’s all we know." Does anyone know why this might be happening? If I create a regular LinkButton control and set an OnClick event to Response.Redirect("http://www.newegg.com") it works just fine.

Aeternus
  • 45
  • 5

3 Answers3

0

Better not use PostBackUrl, and use instead ImageButton or LinkButton with image inside.

MoustafaS
  • 1,991
  • 11
  • 20
0

The code you posted is not sending a link to Newegg. Instead, you are cross site scripting to Newegg.

In other words, you are doing HttpPost instead of HttpGet. I don't think Newegg will let you do to their sites.

If you just want a link to other site, you can simply use HyperLink.

<asp:HyperLink runat="server" ID="MyHyperLink" ></asp:HyperLink>

if (TotalWattage > 1 && TotalWattage < 275)
{
    MyHyperLink.ImageUrl = "~/Images/PSU Tool Images/CM-300.jpg";
    MyHyperLink.Text = "300w COOLMAX CM-300";
    MyHyperLink.NavigateUrl = "http://www.newegg.com";
}
Win
  • 61,100
  • 13
  • 102
  • 181
  • Ok thanks for the suggestion. Interestingly, I did exactly that and it still broke in the same way. [I found this past post](http://stackoverflow.com/questions/23155927/javascript-critical-error-at-line-5-column-9-in-unknown-source-location) and set IE to -extoff for no addons and it (your method) works just fine when I disable IE addons. – Aeternus Jun 24 '16 at 02:36
0

All the answers so far require you to change your markup code to add a new item or change the item type that you are using, there can be downsides to this in certain implementations. If you know the user has Javascript enabled you can use "window.location.href" to redirect the user to your target page:

if (TotalWattage > 1 && TotalWattage < 275) //depending on wattage calculation, shows PSU recommendation
    {
        imgbtnPSURecommend.ImageUrl = "~/Images/PSU Tool Images/CM-300.jpg";
        lblPSURecommend.Text = "300w COOLMAX CM-300";
        imgbtnPSURecommend.OnClientClick = "window.location.href = 'http://www.newegg.com'; return false;"
    }
David Rogers
  • 2,601
  • 4
  • 39
  • 84