This is a discussion on Call Serverside Function from A Tag within the .Net Development forums, part of the Programming & Scripting category; hi guys, I am busy creating my first .Net website and I have another problem. I have a catalogue page, ...
| |||||||
|
#1
| |||
| |||
| hi guys, I am busy creating my first .Net website and I have another problem. I have a catalogue page, see attached, the feature title on the right is always the first title of the results, but when I click on another title, I would like that feature title on the right to change, I have tried a tags, linkbutton, asp:hyperlink, and not getting it to work, here is the a tag example: Code: <a id="a_changeFeature" onclick="change_Feature('<%#Container.DataItem("ISBN13")%>')" runat="server"><%#Container.DataItem("rm_TL")%></a>
Code: <a id="a_changeFeature" onclick="change_Feature('9781919855295')" runat="server">Turning Points in History</a>
Code: Public Sub change_Feature(ByRef str_ISBN As String)
Dim con As New SqlConnection("****")
Dim strSQL As String = "SELECT * FROM intranet_EdtPublication WHERE ISBN13 = '" & str_ISBN & "'"
Dim cmd As New SqlCommand(strSQL, con)
con.Open()
Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
rpt_Feature_Title.DataSource = sqlReader
rpt_Feature_Title.DataBind()
End Sub
Last edited by noFriends; June 29th, 2009 at 05:19 AM. Reason: add image |
|
#2
| ||||
| ||||
| If your sub is in code behind then you need to use a .NET control to call it. I would suggest a <asp:linkbutton> control. You wouldn't pass a value to the sub, you normally have something like:- Code: public sub change_feature(ByVal s as object, ByVal e as EventArgs) end sub The way you have it at the moment is more the way you'd call a JS function.
__________________ Join the folding team |
|
#3
| |||
| |||
| Hi RR, it is in a asp:Repeater, I need to pass the value of the ISBN to the function so that I know which one to load. Code: <asp:Repeater ID="rpt_Catalogue" runat="server">
<ItemTemplate>
<div id="catalogue_row">
<a id="a_changeFeature" onclick="change_Feature('<%#Container.DataItem("ISBN13")%>')" runat="server"><%#Container.DataItem("rm_TL")%></a><br />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
|
|
#4
| ||||
| ||||
| OK. Had a quick recap on one of my apps and I think this is the way to handle it. Code: <asp:repeater id="rep1" runat="server" onitemcommand="rep1OnItemCommand">
<itemtemplate>
<asp:linkbutton id="lnk1" runat="server" CommandName="link" CommandArgument="<%#Container.DataItem("ISBN13")%>" />
</itemtemplate>
</asp:repeater>
Code: Public Sub rep1OnItemCommand(ByVal s as Object, ByVal e as RepeaterCommandEventArgs) if e.CommandName="link" then Dim value as string = e.CommandArgument end if end sub |
|
#5
| |||
| |||
| mmm, strange, it doesn't show on my page? even though when I look at the source code it shows: Code: <asp:LinkButton CommandName="change_Feature" CommandArgument="9781919855295" runat="server" Text="Turning Points in History" /><br /> Code: <asp:Repeater ID="rpt_Catalogue" runat="server" OnItemCommand="Cat_OnItemCommand">
<ItemTemplate>
<asp:LinkButton CommandName="change_Feature" CommandArgument="<%#Container.DataItem("ISBN13")%>" runat="server" Text="<%#Container.DataItem("rm_TL")%>" /><br />
<%#Container.DataItem("strDesc")%>
</div>
</ItemTemplate>
</asp:Repeater>
Code: Public Sub Cat_OnItemCommand(ByVal s As Object, ByVal e As RepeaterCommandEventArgs)
If e.CommandName = "change_Feature" Then
Dim con As New SqlConnection("****")
Dim strSQL As String = "SELECT * FROM intranet_EdtPublication WHERE sap_IS13 = '" & e.CommandArgument & "'"
Dim cmd As New SqlCommand(strSQL, con)
con.Open()
Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
rpt_Feature_Title.DataSource = sqlReader
rpt_Feature_Title.DataBind()
End If
End Sub
|
|
#7
| |||
| |||
| Last edited by noFriends; June 29th, 2009 at 06:10 AM. |
|
#8
| ||||
| ||||
| Hmmm....Something is definitely not right with that... ![]() Not entirely sure why the repeater seems to be doing it's job but then it's not rendering the linkbutton correctly... Could you post the whole .aspx page (and code behind if you have it) |
|
#9
| |||
| |||
| ok, here is the aspx page: Code: <%@ Page Language="VB" Debug="true" AutoEventWireup="true" CodeFile="catalogue.aspx.vb" Inherits="catalogue" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>--Pearson Education--</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="include/p_l1.css" type="text/css" rel="stylesheet">
<script language="javascript">
<!--
sfHover = function() {
var sfEls = document.getElementById("cat_nav_items").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
-->
</script>
</head>
<body onLoad="javascript:call startList;">
<div id="wrapper">
<div id="header"><img src="images/header.jpg"></div>
<div id="maincontent">
<!--#include file="include/l1_header.aspx"-->
<asp:image runat="server" id="img_Header" ></asp:image>
<%=Session("strMenu")%>
<div id="catalogue_section">
<form id="frmCat" runat="server">
<br/>
<br/>
<asp:image runat="server" id="img_CatHeader" ></asp:image><br />
<asp:Repeater ID="rpt_Catalogue" runat="server" OnItemCommand="Cat_OnItemCommand">
<ItemTemplate>
<div id="catalogue_row">
<div id="catalogue_row_image">
<asp:image Width="62px" CssClass="catalogue_image" BorderColor="Black" BorderWidth="1px" runat="server" ImageUrl='<%#check_Image(Databinder.Eval(Container.DataItem, "ISBN13"))%>' ></asp:image>
</div>
<div id="catalogue_row_text">
<asp:LinkButton ID="lb_Change" CssClass="body_text" CommandName="change_Feature" CommandArgument="<%#Container.DataItem("ISBN13")%>" runat="server" Text="<%#Container.DataItem("rm_TL")%>" /><br />
<%#Container.DataItem("strDesc")%>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</div>
<div id="feature_title_right">
<asp:image style="float:left;" runat="server" id="img_khari_buy" ImageUrl="images/kalahari_ENG.gif" ></asp:image>
<asp:image style="float:right; padding-right:10px;" runat="server" id="img_look_inside" ImageUrl="images/inside_ENG.gif" ></asp:image>
<br /><br /><br />
<asp:Repeater ID="rpt_Feature_Title" runat="server">
<ItemTemplate>
<asp:image Width="173px" CssClass="catalogue_image" BorderColor="Black" BorderWidth="1px" runat="server" ImageUrl='<%#check_Image(Databinder.Eval(Container.DataItem, "ISBN13"))%>' ></asp:image>
<br /><br />
<strong><%#DataBinder.Eval(Container.DataItem, "rm_TL")%></strong><br />
<%#check_Display_Data("Author", Databinder.Eval(Container.DataItem, "rm_AU"))%><br />
<%#check_Display_Data("ISBN", DataBinder.Eval(Container.DataItem, "ISBN13"))%><br />
<br />
<%#check_Display_Data("Imprint", DataBinder.Eval(Container.DataItem, "rm_IM"))%><br />
<%#check_Display_Data("Publication Date", DataBinder.Eval(Container.DataItem, "rm_PDSAF"))%><br />
<%''#check_Display_Data("Age Group", DataBinder.Eval(Container.DataItem, "rm_RM"))%><br />
<br />
<%#check_Display_Data("Extent", DataBinder.Eval(Container.DataItem, "rm_PP"))%>pp<br />
<%''#check_Display_Data("Format", DataBinder.Eval(Container.DataItem, "rm_PS"))%><br />
<%#check_Display_Data("Mass", DataBinder.Eval(Container.DataItem, "rm_WT"))%>gm<br />
<br />
<%#check_Display_Data("Description", DataBinder.Eval(Container.DataItem, "rm_DE"))%><br />
<br />
<%''#check_Display_Data("Price (incl. VAT)", DataBinder.Eval(Container.DataItem, "rm_PRRND"))%>
</ItemTemplate>
</asp:Repeater>
</div>
<div id="footer_blueline"></div>
</div>
<div id="footer">
<div id="footer_maintext">Copyright Pearson Education. All rights reserved. Legal and Privacy Notice. Prices subject to change</div>
<div id="footer_sitemap">Site map</div>
</div>
</div>
</body>
</html>
Code: Imports System.Data.SqlClient
Partial Class catalogue
Inherits System.Web.UI.Page
Dim strCatType As String
Sub Page_Load()
strCatType = Request.QueryString("c")
Fill_Catalogue(strCatType)
Fill_Feature(strCatType)
End Sub
Public Sub Fill_Catalogue(ByVal strCatType As String)
Dim con As New SqlConnection("*****")
Dim strSQL As String = "SELECT top 5 sap_IS13 as ISBN13, rm_TL, left(rm_DE,150) + '...' as strDesc FROM intranet_EdtPublication WHERE rm_DE IS NOT NULL"
Dim cmd As New SqlCommand(strSQL, con)
con.Open()
Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
rpt_Catalogue.DataSource = sqlReader
rpt_Catalogue.DataBind()
End Sub
Public Function check_Image(ByVal inISBN13 As String) As String
If Right(inISBN13, 1) = "5" Then
check_Image = "images/covers/001.jpg"
Else
check_Image = "images/covers/000.jpg"
End If
End Function
Public Sub Fill_Feature(ByVal strCatType As String)
Dim con As New SqlConnection("*****")
Dim strSQL As String = "SELECT top 1 sap_IS13 as ISBN13, * FROM intranet_EdtPublication WHERE rm_DE IS NOT NULL"
Dim cmd As New SqlCommand(strSQL, con)
con.Open()
Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
rpt_Feature_Title.DataSource = sqlReader
rpt_Feature_Title.DataBind()
End Sub
Public Function check_Display_Data(ByVal str_Label As String, ByVal str_Value As String) As String
Dim str_Display As String = ""
If str_Value <> "" Then
If str_Label = "Publication Date" Then
str_Display = "<strong>" & str_Label & ":</strong> " & Day(str_Value) & "/" & Month(str_Value) & "/" & Year(str_Value)
Else
str_Display = "<strong>" & str_Label & ":</strong> " & str_Value
End If
End If
check_Display_Data = str_Display
End Function
Public Sub Cat_OnItemCommand(ByVal s As Object, ByVal e As RepeaterCommandEventArgs)
If e.CommandName = "change_Feature" Then
Dim con As New SqlConnection("*****")
Dim strSQL As String = "SELECT * FROM intranet_EdtPublication WHERE sap_IS13 = '" & e.CommandArgument & "'"
Dim cmd As New SqlCommand(strSQL, con)
con.Open()
Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
rpt_Feature_Title.DataSource = sqlReader
rpt_Feature_Title.DataBind()
End If
End Sub
End Class
Thanks for all the help, really appreciate it. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to call a .js file in my form? | dtz | JavaScript Programming | 9 | July 28th, 2009 06:28 AM |
| Help with JS function | Wolffy | JavaScript Programming | 1 | June 9th, 2009 09:52 AM |
| [Functions] Help using function | Rebelle | ASP Development | 11 | October 13th, 2008 12:13 PM |
| without function | guddu | Microsoft SQL Server | 1 | July 15th, 2008 04:02 PM |