Link to home
Start Free TrialLog in
Avatar of jtcy
jtcy

asked on

ASP.NET: ImageButton to open New Window

I have this:

<asp:ImageButton ID="imbJoin" CssClass="btn-find" AlternateText="Find" ToolTip="Find" runat="server" ImageUrl="~/library/btn-find.gif" onClick="javascript:popUp('ServicesLocator.aspx')" />

and when running, it says:

Compiler Error Message: CS1012: Too many characters in character literal
Avatar of imateyelectronics
imateyelectronics
Flag of United States of America image

You need to change the Onclick to javascript("ServicesLocator.aspx")

In C# or vb using single quotesonly for chars or a s ingle character you need double quotes for strings.
Avatar of jtcy
jtcy

ASKER

But then how would it know what function to call? The function name is PopUp
I'm sorry I should have been more specific.. Everything that you have done is correct except the single quotes within the javascript call,  Your asp:button call should be this:

<asp:ImageButton ID="imbJoin" CssClass="btn-find" AlternateText="Find" ToolTip="Find" runat="server" ImageUrl="~/library/btn-find.gif" onClick="javascript:popUp("ServicesLocator.aspx")" />
@jtcy: what's in the popUp function?

you might need to change your code behind as...

  imbJoin.Attributes.Add("onclick", "popUp('ServicesLocator.aspx');" )

and remove

  onClick="javascript:popUp('ServicesLocator.aspx')"
Avatar of jtcy

ASKER

The thing is, I dont want it to do a postback (refresh).
then just use an HTML image button not a server-side button.
ASKER CERTIFIED SOLUTION
Avatar of PatHyatt
PatHyatt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin