|
|
|
start date: Wed, 01 Aug 2007 11:48:45 -0000,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
unknown
|
|
2
Göran Andersson
|
|
3
unknown
|
|
4
Mark Rae [MVP]
|
|
5
Teemu Keiski
|
|
6
unknown
|
|
7
Mark Rae [MVP]
|
|
8
Göran Andersson
|
|
9
unknown
|
|
10
Teemu Keiski
|
|
11
unknown
|
|
12
Teemu Keiski
|
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
Date:Wed, 01 Aug 2007 11:48:45 -0000
Author:
|
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");
--
Gran Andersson
_____
http://www.guffa.com
Date:Wed, 01 Aug 2007 14:22:38 +0200
Author:
|
Re: Call .cs method/function from .ascx
On 1 Aug, 13:13, "Mark Rae [MVP]" wrote:
> wrote in message
>
> news:1185968925.655851.140200@r34g2000hsd.googlegroups.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
Date:Wed, 01 Aug 2007 12:34:57 -0000
Author:
|
Re: Call .cs method/function from .ascx
wrote in message
news:1185971697.633789.210950@l70g2000hse.googlegroups.com...
Does this work:?
<asp:PlaceHolder ID="litTest"
runat="server"><%=MyMethod("testargs")%></asp:PlaceHolder>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Wed, 1 Aug 2007 14:45:43 +0100
Author:
|
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
wrote in message
news:1185968925.655851.140200@r34g2000hsd.googlegroups.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
>
Date:Wed, 1 Aug 2007 17:49:06 +0300
Author:
|
Re: Call .cs method/function from .ascx
On 1 Aug, 14:45, "Mark Rae [MVP]" wrote:
> wrote in message
>
> news:1185971697.633789.210950@l70g2000hse.googlegroups.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
Date:Wed, 01 Aug 2007 14:53:32 -0000
Author:
|
Re: Call .cs method/function from .ascx
On 1 Aug, 15:49, "Teemu Keiski" 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
>
> wrote in message
>
> news:1185968925.655851.140200@r34g2000hsd.googlegroups.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 :)
Date:Wed, 01 Aug 2007 14:54:53 -0000
Author:
|
Re: Call .cs method/function from .ascx
wrote in message
news:1185980012.258138.22350@d55g2000hsg.googlegroups.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
Date:Wed, 1 Aug 2007 16:13:03 +0100
Author:
|
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
wrote in message
news:1185980093.068391.124570@k79g2000hse.googlegroups.com...
> On 1 Aug, 15:49, "Teemu Keiski" 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
>>
>> wrote in message
>>
>> news:1185968925.655851.140200@r34g2000hsd.googlegroups.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 :)
>
Date:Wed, 1 Aug 2007 18:13:27 +0300
Author:
|
Re: Call .cs method/function from .ascx
On 1 Aug, 16:13, "Mark Rae [MVP]" wrote:
> wrote in message
>
> news:1185980012.258138.22350@d55g2000hsg.googlegroups.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 MVPhttp://www.markrae.net
My bad, sorry.
Yeah that works, but when i try and do it in an attribute it doesnt :(
Thanks
Andrew
Date:Wed, 01 Aug 2007 15:35:54 -0000
Author:
|
Re: Call .cs method/function from .ascx
Yup,
because <%= %> is resolved when the Page is rendered, so it's target cannot
be server-side property (which basically such attribute represents on server
control)
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
wrote in message
news:1185982554.300572.194500@l70g2000hse.googlegroups.com...
> On 1 Aug, 16:13, "Mark Rae [MVP]" wrote:
>> wrote in message
>>
>> news:1185980012.258138.22350@d55g2000hsg.googlegroups.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 MVPhttp://www.markrae.net
>
> My bad, sorry.
>
> Yeah that works, but when i try and do it in an attribute it doesnt :(
>
> Thanks
>
> Andrew
>
Date:Wed, 1 Aug 2007 19:54:13 +0300
Author:
|
Re: Call .cs method/function from .ascx
trullock@googlemail.com wrote:
> On 1 Aug, 16:13, "Mark Rae [MVP]" wrote:
>> wrote in message
>>
>> news:1185980012.258138.22350@d55g2000hsg.googlegroups.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 MVPhttp://www.markrae.net
>
> My bad, sorry.
>
> Yeah that works, but when i try and do it in an attribute it doesnt :(
>
> Thanks
>
> Andrew
>
Why do you have to put it in a Literal control? Just do:
<%=MyMethod("testargs")%>
--
Gran Andersson
_____
http://www.guffa.com
Date:Wed, 01 Aug 2007 22:08:35 +0200
Author:
|
|
|