Solved

passing the value of a container.dataitem as a parameter in a javascript function inside a hyperlink control?

Posted on 2004-09-28
8
2,108 Views
Last Modified: 2008-01-09
Hi There,

I am wanting to call a javascript function from inside a hyperlink control, the function works fine Its just not working when I try to put the value of a       Container.DataItem inside it. Is it legal to do this? I guess I'm probably missing a comma or something.

Sean - thanks in advance                  

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

Expert Comment

by:viola123
ID: 12176738
follow this:

<a class="partname" href="partdetail.aspx" onclick="hideQstring('pt_recno', '<%# DataBinder.Eval(Container.DataItem, "pt_recno") %>')" target="_blank"><%# DataBinder.Eval(Container.DataItem, "pt_shortdesc") %></a>

cheers
viola
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176740
and:

<IMG SRC="<%# findImage(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "pt_recno"))) %>" align="absMiddle" border="0"/>
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176750
i don't think you have to use &quot;  

both of the two codes above are working on my page. so i believe yours should be all right.

cheers
viola
0
 
LVL 6

Accepted Solution

by:
viola123 earned 500 total points
ID: 12176765
try these two:

1.
<asp:HyperLink runat="server" Text="<%# DataBinder.Eval(Container.DataItem, 'shopname')%>" onClick="javascript:RefreshParent('<%# DataBinder.Eval(Container.DataItem, "shop")%>')" ID="Hyperlink1"/>

2.
<a onClick="RefreshParent('<%# DataBinder.Eval(Container.DataItem, "shop")%>')">
<%# DataBinder.Eval(Container.DataItem, 'shopname')%>
</a>

regards,
viola
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:boulder_bum
ID: 12176772
"Is it legal to do this?"

Yes.

As mentioned, &quot; should instead be a " (quotation mark).

Also, I've had problems before using double instead of single quotes for elements when binding (hopefully Microsoft has the problem fixed by now) so if you're still getting a funky error try changing:

Text="<%# ... %>"

  -to-

Text='<%# ... %>'
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176796
my experience on that is:

text = "<%#...'myfunction("para")'%>"


wish it help

viola123
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12177135
In your databinding for the text property of the hyperlink, you are binding to "shopname" and then for your js call, you are binding to "shop".  Is this right?  Should "shop" be "shopname"?

Also, an option would be to have the column with the "shop" value you want to pass to RefreshParent() as a column in your grid (I am assuming that is your container?) that is marked as not visible.  Let's say that is column index #1.  You could use the ItemDataBound event and code like this:

if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{
     // resolve hyper link.  assuming it is in colunm index 2.  make sure you give your hyperlink control an id string (i'll use "hyperlinkName").
     HyperLink link = (HyperLink)e.Item.Cells[2].FindControl("hyperlinkName");

     // set NavigateUrl
     string shop = e.Item.Cells[1].Text;
     link.NavigateUrl = "javascript:RefreshParent('" + shop + "');";
}

John
0
 
LVL 5

Author Comment

by:bullrout
ID: 12177169
Hi guys, thanks for all the answers. The website is brillant for asp .net beginners like myself.

I appreciate the help.

Sean
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

13 Experts available now in Live!

Get 1:1 Help Now