Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Call .cs method/function from .ascx

Reply
Thread Tools

Call .cs method/function from .ascx

 
 
trullock@googlemail.com
Guest
Posts: n/a
 
      08-01-2007
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

 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-01-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      08-01-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
trullock@googlemail.com
Guest
Posts: n/a
 
      08-01-2007
On 1 Aug, 13:13, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-01-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

Does this work

<asplaceHolder ID="litTest"
runat="server"><%=MyMethod("testargs")%></asplaceHolder>


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      08-01-2007
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



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
trullock@googlemail.com
Guest
Posts: n/a
 
      08-01-2007
On 1 Aug, 14:45, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) oups.com...
>
> Does this work
>
> <asplaceHolder ID="litTest"
> runat="server"><%=MyMethod("testargs")%></asplaceHolder>
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net



'System.Web.UI.WebControls.Literal' does not allow child controls.



Andrew

 
Reply With Quote
 
trullock@googlemail.com
Guest
Posts: n/a
 
      08-01-2007
On 1 Aug, 15:49, "Teemu Keiski" <(E-Mail Removed)> 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
>
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-01-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...

>> Does this work
>>
>> <asplaceHolder ID="litTest"
>> runat="server"><%=MyMethod("testargs")%></asplaceHolder>
>>
>> --
>> Mark Rae
>> ASP.NET MVPhttp://www.markrae.net

>
> 'System.Web.UI.WebControls.Literal' does not allow child controls.


Once again - does this work

<asplaceHolder ID="litTest"
runat="server"><%=MyMethod("testargs")%></asplaceHolder>

Please read carefully...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      08-01-2007
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



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On 1 Aug, 15:49, "Teemu Keiski" <(E-Mail Removed)> 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
>>
>> <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Manager limit call duration nazgulero Cisco 0 10-25-2005 06:58 AM
How to make landline call to another landline then out call long distance? jt VOIP 6 01-30-2005 03:57 AM
RMI: remote call or local call Buu Nguyen Java 5 09-17-2004 08:05 AM
help: need to call call web service from java bill sandner Java 1 07-01-2004 02:57 PM
call by address vs. call by value hasho C Programming 35 02-11-2004 08:20 PM



Advertisments