Solved

calling a javascript function with an asp hyperlink control?

Posted on 2004-09-22
4
20,334 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
ID: 12122371
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
ID: 12122702
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
ID: 12123288
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
ID: 12127215
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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