Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > OnClientClick inside Repeater View modes: 
User avatar
Member
Member
AlgarveWeb - 4/29/2011 2:40:22 AM
   
OnClientClick inside Repeater
Hi

I would like to gather some statistics when somebody clicks on a Href inside a Repeater.

Let say that I have something like that in my Transformation

<a href="http://www.algarveweb.com" onclick="AddStat">Select</a>

and now I need the unique ID of the selected Record and send it to a Stored Procedure.

Right now I am sending the click to another page (<a href="~/go/link.aspx?ID=<%# Eval("link_id") %>" target="_blank"><%#Eval("link_title")%></a>) which then looks up the ID details and redirects to the proper web-site.

But thats not very practical since the real URL is not shown on my web-site.

Any ideas, thanks, Mike.

User avatar
Member
Member
AlgarveWeb - 5/2/2011 3:18:59 AM
   
RE:OnClientClick inside Repeater
I did some tests over the weekend and got this working in inside a Static Text Web-Part:

<a href="http://www.algarveweb.com" onclick="{#awb_stat_test#}" target="_blank">Visit Web-Site</a>

where {#awb_stat_test#} inserts the Statistics into the dababase, but this happens on Page Load and not onclick!

When I insert the same code in a repeater it does not do anything and I get an Error Code:

Message: Invalid character
Line: 87
Char: 3
Code: 0
URI: http://localhost/awbdirectory/Site.aspx

which is strange since Char 3 is the < of <a href=....

can anybody help plesae, many thanks, Mike.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 5/2/2011 5:36:34 AM
   
RE:OnClientClick inside Repeater
Hi,

maybe it would be easier if you used Web Analytics module. Then you could use campaigns which could count visits per each link. The URL would not have be modified, only query parameter has to be added.

Is this solution suitable for you?

Best regards,
Ivana Tomanickova

User avatar
Member
Member
AlgarveWeb - 5/2/2011 5:43:31 AM
   
RE:OnClientClick inside Repeater
Thanks, but Web Analytics Campaigns are for incoming links whilst I need to store outgoing links.

Mike

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 5/2/2011 7:44:53 AM
   
RE:OnClientClick inside Repeater
Hi,

as for the error message in a macro resolution (inside transformation). Following code should resolve the macro correctly:

onlclick'<%= CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{#macro#}").ToString() %>'

The javascript onclick method should fire without any issue. But this will not be working if javascript is disabled on the user side.

Alternative solution is to create a custom webpart an use a link button control instead. Then in the code behind (onClick method) you could run custom report logging code. This way you could create a custom report.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
AlgarveWeb - 5/2/2011 8:24:24 AM
   
RE:OnClientClick inside Repeater
Hi Ivana,

Thanks, I tried that and have 2 questions:

If I use this

<asp:LinkButton ID="LinkButton1" runat="server" onClientClick="window.open('http://www.asp.net')" OnClick="LinkButton2_Click">LinkButton</asp:LinkButton>

it works fine, but how do I get the URL from the DB, if I use this

<asp:LinkButton ID="LinkButton2" runat="server" onClientClick="window.open('<%# Eval("Site") %>')" OnClick="LinkButton2_Click">LinkButton</asp:LinkButton>

its not working!

Also, how do I pass a value to LinkButton2_Click?

Many thanks, Mike.

User avatar
Member
Member
AlgarveWeb - 5/2/2011 8:38:13 AM
   
RE:OnClientClick inside Repeater
BTW I tried

<a href="http://www.algarveweb.com" onclick='<%= CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{#awb_stat_test#}").ToString() %>' target="_blank">Visit Web-Site</a>

and it does the same thing as before: All items in the Repeater are insterted as Statistics but no onclick event is working.

Mike

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 5/4/2011 3:42:24 AM
   
RE:OnClientClick inside Repeater
Hi,

you could add a link button into transformation used by repeater displaying your documents. The redirection is managed in the code behind.


<script runat="server">
protected void LinkButton1_Click(object sender, EventArgs e)
{
//TODO: Logging code

//Redirection
UrlHelper.Redirect("http://" + lnkButton.Text);
}

</script>

<asp:LinkButton ID="lnkButton" text='<%# Eval("Site") %>' runat="server" onclick="LinkButton1_Click"><%# Eval("Site") %></asp:LinkButton>



Best regards,
Ivana Tomanickova

User avatar
Member
Member
AlgarveWeb - 5/5/2011 5:56:41 AM
   
RE:OnClientClick inside Repeater
Hi Ivana

Many thanks, I will give it a try.

Mike