Link to home
Start Free TrialLog in
Avatar of bullrout
bullrout

asked on

Calling a javascript function in an asp .net hyperlink?

Hi There,

I was wondering how I can call an open window function in an asp .net hyperlink? Does anyone have any samples?

Sean

<asp:HyperLink id="HyperLink3" style="font-size:xxsmall" Text='<%# DataBinder.Eval(Container.DataItem, "model") %>' NavigateUrl='<%# "ListingDetails.aspx?ListingID=" & DataBinder.Eval(Container.DataItem, "listingID")%>' runat="server" />
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

You will need to use JavaScript code that is be added as a custom attributes in the code behind. Example:

MyHyperLink.Attributes.Add("OnClick","javascript:window.open('MyPage.aspx');");

Best, Nauman
Avatar of bullrout
bullrout

ASKER

Hi Nauman,

I am not using an application, I am using aspx pages that have no code behind. Does this mean I can create a custom open window function and then call it using the method you described?

An also, can I store a querystring value in it ? or is this illegal?

Sean

MyHyperLink.Attributes.Add("OnClick","javascript:window.open('MyPage.aspx?id=<%# DataBinder.Eval(Container.DataItem, "id") %>');");
Do you need a controlled-size popup that you would get from a JavaScript window.open call?  Or just an arbitrary new window?

The <asp:HyperLink> does take a Target attribute that can be used to direct the linked-to page to a new or existing window/frame.  E.g.,

    <asp:HyperLink ... Target="_blank" />

Although this doesn't give you any control over the size or chrome-features of the new window.

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolshyperlinkclasstargettopic.asp
ASKER CERTIFIED SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

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
Hi Thogek,

I will give this a try and let you know how I get on.

Sean