Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Call .cs method/function from .ascx (http://www.velocityreviews.com/forums/t526177-call-cs-method-function-from-ascx.html)

trullock@googlemail.com 08-01-2007 11:48 AM

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


Mark Rae [MVP] 08-01-2007 12:13 PM

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


=?ISO-8859-1?Q?G=F6ran_Andersson?= 08-01-2007 12:22 PM

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

trullock@googlemail.com 08-01-2007 12:34 PM

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



Mark Rae [MVP] 08-01-2007 01:45 PM

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


Teemu Keiski 08-01-2007 02:49 PM

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
>




trullock@googlemail.com 08-01-2007 02:53 PM

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


trullock@googlemail.com 08-01-2007 02:54 PM

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 :)


Mark Rae [MVP] 08-01-2007 03:13 PM

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


Teemu Keiski 08-01-2007 03:13 PM

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 10:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.