sj1187534 Posted December 20, 2003 Posted December 20, 2003 Hi...I am trying to call a function in the code-behind from the HTML side of the page using the asp tags <% .. %>. Can anyone tell me if we can do that and how? SJ Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 Create a Public function and call it like this.. (you can do the same thing with public variables as well) <% =myFunction()%> 'code-behind Public function myFunction() as string return "some value" end function Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 Hi...this is how I am trying to call the function in the code-behind: <asp:TemplateColumn HeaderStyle-Width="150px" SortExpression="name" HeaderText="Bar" ItemStyle-BackColor="BlanchedAlmond"> <ItemTemplate> <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='<%# "/GB.Web/BarOwner/BarProfile.aspx?id=" & =StringOperations.Encrypt(DataBinder.Eval(Container.DataItem,"idNum"))%>'> </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn> And I am getting this error: BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments. Can u tell me whats wrong... The StringOperations is a class where the Encrypt() is a shared function which takes an integer and returns a string SJ Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 replace StringOperations.Encrypt with your own function and then in that new function call StringOperations.Encrypt. Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 Nope..not working...giving me the same error SJ Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 A couple of " and & were miss-placed <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='/GB.Web/BarOwner/BarProfile.aspx?id=<%# =myFunction(DataBinder.Eval(Container.DataItem,"idNum"))%>' ID="Hyperlink1" NAME="Hyperlink1"> Quote Visit...Bassic Software
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 Sorry, I just noticed something... you don't need the DataBinder.. do this instead.. <%# myFunction(Container.DataItem("idNum"))%> Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 Now...it is not giving me any error but whatever is in the asp tags is being displayed as string!!!! Like this--- Profile.aspx?id=<%# =Encrypt(DataBinder.Eval(Container.DataItem,"idNum"))%> Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 Did you paste exactly this ... It does work for me as is. <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='/GB.Web/BarOwner/BarProfile.aspx?id=<%# myFunction(Container.DataItem("idNum"))%>' ID="Hyperlink1" ></asp:HyperLink> Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 this is what I have .... <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='/GB.Web/BarOwner/BarProfile.aspx?id=<%# Encrypt(DataBinder.Eval(Container.DataItem,"idNum"))%>' > </asp:HyperLink> I even tried with the '=' sign before the Encrypt() function like this <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='/GB.Web/BarOwner/BarProfile.aspx?id=<%# =Encrypt(DataBinder.Eval(Container.DataItem,"idNum"))%>' > </asp:HyperLink> Its not working..still showing the string!!!! Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 As I posted "you don't need the DataBinder" Try the code as is in my last post Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 Bad news!!! I am sorry about the last one...I tried like this now... <asp:HyperLink Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"name")%>' NavigateUrl='/GB.Web/BarOwner/BarProfile.aspx?id=<%# Encrypt(Container.DataItem("idNum"))%>' > </asp:HyperLink> Not working!!!! By the way...I forgot to ask u....the MyFunction() function u are trying, is it in the code-behind or did u write that function in the HTML page itself? SJ Quote
Moderators Robby Posted December 20, 2003 Moderators Posted December 20, 2003 Always code behind. By the way, copy/paste my sample because once again you are off. Quote Visit...Bassic Software
sj1187534 Posted December 20, 2003 Author Posted December 20, 2003 Hi..I appreciate ur patience....but i am sorry that i didn't find any difference between ur code and mine...except the way u closed the tags...i tried that too but it just doesn't work. SJ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.