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,266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

624 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