Solved

calling a javascript function with an asp hyperlink control?

Posted on 2004-09-22
4
20,258 Views
Last Modified: 2011-09-20
Hi there,

I wanted to know the syntax for calling a js function inside an asp hyperlink control?

Sean - thanks in advance


<asp:HyperLink runat="server" Text="<%# DataBinder.Eval(Container.DataItem, &quot;shopname&quot;)%>" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "shop")%>' ID="Hyperlink1" NAME="Hyperlink1"/></td>
0
Comment
Question by:bullrout
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:daffodils
daffodils earned 166 total points
Comment Utility
HyperLink control does not expose any events.

It might be better to call use a LinkButton and then add the javascript function call as an attribute.

In the Page_Load
 
 myLinkButton.Attributes.Add("onclick", "someJavascriptFuncion();");

0
 
LVL 18

Accepted Solution

by:
tusharashah earned 168 total points
Comment Utility
The method shown above is perfect, but you can even call JavaScript using following method:

------------------------------------------------------------------------------------------------

function openexample()
{
    var props = 'location=no,menubar=no,toolbar=no,height=500,width=500';
    window.open('example.pdf,'Example',props,true);
}

<td><asp:hyperlink id="lnkpdf" runat="server" target="_blank" navigateurl="javascript:openexample();">example</asp:hyperlink></td>

------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 8

Expert Comment

by:daffodils
Comment Utility
Hey bullrout,

Haven't you asked this question before?? what's with that solution ??
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21074951.html
0
 
LVL 10

Assisted Solution

by:jnhorst
jnhorst earned 166 total points
Comment Utility
bullrout:

With a hyperlink control you can set the NavigateUrl property to call the js function like this:

hl.NavigateUrl = "javascript:fnName();"

Assuming here the fnName is the name of the function.  You could, of course, pass parameters to the js function as needed.

daffodils is right also that the LinkButton control can be used.  The LinkButton control renders to the browser as an <a> tag.  The href="..." attribute of the <a> calls the __doPostBack() JavaScript routine that is written to the browser by ASP.NET to fire the postback.  So if you add an onclick event as daffodils shows, you can call another js routine *before* the postback happens.  I like to use this to disable the link button client-side before the postback to guarantee no further clicks on the button.

John
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now