![]() |
Call .cs method/function from .ascx
Hi,
Is there a way to call a codebehind method/function from an attribute of a runat=server tag, kinda like this: <asp:Literal runat="server" ID="litTest" Text='<%# MyMethod("testargs") %>' /> but obviously that doesn't work :( Thanks Andrew |
Re: Call .cs method/function from .ascx
<trullock@googlemail.com> wrote in message
news:1185968925.655851.140200@r34g2000hsd.googlegr oups.com... > Is there a way to call a codebehind method/function from an attribute > of a runat=server tag, kinda like this: > > <asp:Literal runat="server" ID="litTest" Text='<%# > MyMethod("testargs") %>' /> > > but obviously that doesn't work :( 1) Make sure MyMethod returns a string 2) Make sure MyMethod has either protected or public scope 3) Change <%# to <%= -- Mark Rae ASP.NET MVP http://www.markrae.net |
Re: Call .cs method/function from .ascx
trullock@googlemail.com wrote:
> Hi, > > Is there a way to call a codebehind method/function from an attribute > of a runat=server tag, kinda like this: > > <asp:Literal runat="server" ID="litTest" Text='<%# > MyMethod("testargs") %>' /> > > but obviously that doesn't work :( > > Thanks > > Andrew I prefer to put the code in the code behind: litTest.Text = MyMethod("testargs"); -- Göran Andersson _____ http://www.guffa.com |
Re: Call .cs method/function from .ascx
On 1 Aug, 13:13, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> <trull...@googlemail.com> wrote in message > > news:1185968925.655851.140200@r34g2000hsd.googlegr oups.com... > > > Is there a way to call a codebehind method/function from an attribute > > of a runat=server tag, kinda like this: > > > <asp:Literal runat="server" ID="litTest" Text='<%# > > MyMethod("testargs") %>' /> > > > but obviously that doesn't work :( > > 1) Make sure MyMethod returns a string > > 2) Make sure MyMethod has either protected or public scope > > 3) Change <%# to <%= > > -- > Mark Rae > ASP.NET MVPhttp://www.markrae.net Hi, I tried that but it just literally writes out: <%= MyMethod("testargs") %> into the resultant html. :( Goran, I cant do that for a complicated reason that i wont rabble on about here. I just need to be able to do it from the html, not the codebehind. Any other ideas anyone? Thanks |
Re: Call .cs method/function from .ascx
<trullock@googlemail.com> wrote in message
news:1185971697.633789.210950@l70g2000hse.googlegr oups.com... Does this work:? <asp:PlaceHolder ID="litTest" runat="server"><%=MyMethod("testargs")%></asp:PlaceHolder> -- Mark Rae ASP.NET MVP http://www.markrae.net |
Re: Call .cs method/function from .ascx
This should work, if you just call litTest.DataBind() in code when you want
it to be "called". <%# refers to a databinding expression when something must call DataBind() for the control for databinding to occur. -- Teemu Keiski AspInsider, ASP.NET MVP http://blogs.aspadvice.com/joteke http://teemukeiski.net <trullock@googlemail.com> wrote in message news:1185968925.655851.140200@r34g2000hsd.googlegr oups.com... > Hi, > > Is there a way to call a codebehind method/function from an attribute > of a runat=server tag, kinda like this: > > <asp:Literal runat="server" ID="litTest" Text='<%# > MyMethod("testargs") %>' /> > > but obviously that doesn't work :( > > Thanks > > Andrew > |
Re: Call .cs method/function from .ascx
On 1 Aug, 14:45, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> <trull...@googlemail.com> wrote in message > > news:1185971697.633789.210950@l70g2000hse.googlegr oups.com... > > Does this work:? > > <asp:PlaceHolder ID="litTest" > runat="server"><%=MyMethod("testargs")%></asp:PlaceHolder> > > -- > Mark Rae > ASP.NET MVPhttp://www.markrae.net 'System.Web.UI.WebControls.Literal' does not allow child controls. :( Andrew |
Re: Call .cs method/function from .ascx
On 1 Aug, 15:49, "Teemu Keiski" <jot...@aspalliance.com> wrote:
> This should work, if you just call litTest.DataBind() in code when you want > it to be "called". <%# refers to a databinding expression when something > must call DataBind() for the control for databinding to occur. > > -- > Teemu Keiski > AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net > > <trull...@googlemail.com> wrote in message > > news:1185968925.655851.140200@r34g2000hsd.googlegr oups.com... > > > Hi, > > > Is there a way to call a codebehind method/function from an attribute > > of a runat=server tag, kinda like this: > > > <asp:Literal runat="server" ID="litTest" Text='<%# > > MyMethod("testargs") %>' /> > > > but obviously that doesn't work :( > > > Thanks > > > Andrew Hi, Yeah i know i can call databind and use a # in the server tags, but i want to avoid any codebehind. (if im calling databind i might as well just do literal.text = "value"; Thanks for the suggestion anyway :) |
Re: Call .cs method/function from .ascx
<trullock@googlemail.com> wrote in message
news:1185980012.258138.22350@d55g2000hsg.googlegro ups.com... >> Does this work:? >> >> <asp:PlaceHolder ID="litTest" >> runat="server"><%=MyMethod("testargs")%></asp:PlaceHolder> >> >> -- >> Mark Rae >> ASP.NET MVPhttp://www.markrae.net > > 'System.Web.UI.WebControls.Literal' does not allow child controls. Once again - does this work:? <asp:PlaceHolder ID="litTest" runat="server"><%=MyMethod("testargs")%></asp:PlaceHolder> Please read carefully... -- Mark Rae ASP.NET MVP http://www.markrae.net |
Re: Call .cs method/function from .ascx
You can also do it on the aspx side if you use <script
runat="server">...</script> block, no need to touch the code-behind ;-) -- Teemu Keiski AspInsider, ASP.NET MVP http://blogs.aspadvice.com/joteke http://teemukeiski.net <trullock@googlemail.com> wrote in message news:1185980093.068391.124570@k79g2000hse.googlegr oups.com... > On 1 Aug, 15:49, "Teemu Keiski" <jot...@aspalliance.com> wrote: >> This should work, if you just call litTest.DataBind() in code when you >> want >> it to be "called". <%# refers to a databinding expression when something >> must call DataBind() for the control for databinding to occur. >> >> -- >> Teemu Keiski >> AspInsider, ASP.NET >> MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net >> >> <trull...@googlemail.com> wrote in message >> >> news:1185968925.655851.140200@r34g2000hsd.googlegr oups.com... >> >> > Hi, >> >> > Is there a way to call a codebehind method/function from an attribute >> > of a runat=server tag, kinda like this: >> >> > <asp:Literal runat="server" ID="litTest" Text='<%# >> > MyMethod("testargs") %>' /> >> >> > but obviously that doesn't work :( >> >> > Thanks >> >> > Andrew > > Hi, Yeah i know i can call databind and use a # in the server tags, > but i want to avoid any codebehind. (if im calling databind i might as > well just do literal.text = "value"; > > Thanks for the suggestion anyway :) > |
| All times are GMT. The time now is 03:11 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.