I understand how code-behind can handle events for a page, but can I call a
code-behind method from within a <script> tag in my ASP.Net page, or can I
only call methods defined in other <script> sections? I can't seem to
figure out the syntax for for calling code-behind directly. The method is
within the class my page inherits from and is public, but when I try to call
it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett- 8 5333
Does your method have a return type? Does it return anything? If it does,
does your line in the <Script> handle a retuned value. Are you using c# or
vb? You say the method is inherited and its public, is the pages class
public?
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I call
a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method is within the class my page inherits from and is public, but when I try to
call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
I've tried with return type and without. When I had return type it did in
fact return a value and the asp side assigned the return to a variable.
I am using C#. Yes the class is public and the method.
So I must be doing something stupid here. From your responses I assume that
it is legal to directly call code-behind methods from within a <script> tag
(as opposed to handling events in code-behind).
-Brett-
"Felbrigg" <so*****@microsoft.com> wrote in message
news:u2**************@TK2MSFTNGP11.phx.gbl... Does your method have a return type? Does it return anything? If it
does, does your line in the <Script> handle a retuned value. Are you using c#
or vb? You say the method is inherited and its public, is the pages class public?
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:e%****************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I
call a code-behind method from within a <script> tag in my ASP.Net page, or can
I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method
is within the class my page inherits from and is public, but when I try to call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
Here is a snippet of my code behind class:
public class WebForm1 : Page
{
public string Hello()
{
return "Hello";
}
}
From my asp page I have a <script> tag mixed within my html that looks like
this:
<script runat=server> string x = Hello(); </script>
With this code I get this error:
CS0120: An object reference is required for the nonstatic field, method, or
property 'Web1.WebForm1.Hello()'
This indicates I am not using the correct syntax for calling code-behind.
Any idea what I'm doing wrong? How do I get an instance of my page object
from within the script tag?
-Brett-
"Felbrigg" <so*****@microsoft.com> wrote in message
news:u2**************@TK2MSFTNGP11.phx.gbl... Does your method have a return type? Does it return anything? If it
does, does your line in the <Script> handle a retuned value. Are you using c#
or vb? You say the method is inherited and its public, is the pages class public?
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:e%****************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I
call a code-behind method from within a <script> tag in my ASP.Net page, or can
I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method
is within the class my page inherits from and is public, but when I try to call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
as long as the script tag has a runat=server (so its server script), it can
call code behind routines. the aspx page subclasses the code behind class,
so methods must be declared as protected or public to be in scope.
-- bruce (sqlwork.com)
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I call
a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method is within the class my page inherits from and is public, but when I try to
call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
I don't think you do understand CodeBehind, because you don't "call" it from
the Page. It IS the Page. The Page Template and the CodeBehind together
constitute a Class definition. The Page Template must inherit the CodeBehind
class (which must inherit System.Web.UI.Page, or a derivative thereof) to
create a complete Page class. In your message, you stated:
"The method is within the class my page inherits from and is public"
If your Page doesn't inherit the CodeBehind class, then it has nothing to do
with it.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I call
a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method is within the class my page inherits from and is public, but when I try to
call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
My page does inherit from the codebehind class and my codebehind class
inherits from System.Web.UI.Page.
What I need to do is call a codebehind method from within a <script> section
in my page layout.
-Brett-
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:OB**************@TK2MSFTNGP09.phx.gbl... I don't think you do understand CodeBehind, because you don't "call" it
from the Page. It IS the Page. The Page Template and the CodeBehind together constitute a Class definition. The Page Template must inherit the
CodeBehind class (which must inherit System.Web.UI.Page, or a derivative thereof) to create a complete Page class. In your message, you stated:
"The method is within the class my page inherits from and is public"
If your Page doesn't inherit the CodeBehind class, then it has nothing to
do with it.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:e#**************@TK2MSFTNGP10.phx.gbl... I understand how code-behind can handle events for a page, but can I
call a code-behind method from within a <script> tag in my ASP.Net page, or can
I only call methods defined in other <script> sections? I can't seem to figure out the syntax for for calling code-behind directly. The method
is within the class my page inherits from and is public, but when I try to call it from my page I get this error:
CS1520: Class, struct, or interface method must have a return type
What am I missing here?
-Brett-
Try this in your aspx page instead:
<% String x = Hello(); %>
A code declaration block (script) is used to declare member variables and
methods in the dynamically generated code behind, which isn't necessarily
generated yet (and, hence, can't inherit from something until it is
generated). A code render block (<% %>) is the appropriate choice here. With
ASP.NET, everything is compiled and not interpreted, even if it is compiled
dynamically.
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl... Here is a snippet of my code behind class:
public class WebForm1 : Page { public string Hello() { return "Hello"; } }
From my asp page I have a <script> tag mixed within my html that looks like this:
<script runat=server> string x = Hello(); </script>
With this code I get this error:
CS0120: An object reference is required for the nonstatic field, method, or property 'Web1.WebForm1.Hello()'
This indicates I am not using the correct syntax for calling code-behind. Any idea what I'm doing wrong? How do I get an instance of my page object from within the script tag?
-Brett-
"Felbrigg" <so*****@microsoft.com> wrote in message news:u2**************@TK2MSFTNGP11.phx.gbl... Does your method have a return type? Does it return anything? If it does, does your line in the <Script> handle a retuned value. Are you using c# or vb? You say the method is inherited and its public, is the pages class public?
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:e%****************@TK2MSFTNGP10.phx.gbl... > I understand how code-behind can handle events for a page, but can I call a > code-behind method from within a <script> tag in my ASP.Net page, or > can I > only call methods defined in other <script> sections? I can't seem to > figure out the syntax for for calling code-behind directly. The method is > within the class my page inherits from and is public, but when I try to call > it from my page I get this error: > > CS1520: Class, struct, or interface method must have a return type > > What am I missing here? > > -Brett- > >
Wow, how unbelievably ignorant of me.
That worked perfectly. My asp inexperience is showing readily now. Thanks
a ton for clearing up such a simple problem.
-Brett-
"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:uq*************@tk2msftngp13.phx.gbl... Try this in your aspx page instead:
<% String x = Hello(); %>
A code declaration block (script) is used to declare member variables and methods in the dynamically generated code behind, which isn't necessarily generated yet (and, hence, can't inherit from something until it is generated). A code render block (<% %>) is the appropriate choice here.
With ASP.NET, everything is compiled and not interpreted, even if it is
compiled dynamically.
-- Chris Jackson Software Engineer Microsoft MVP - Windows Client Windows XP Associate Expert -- More people read the newsgroups than read my email. Reply to the newsgroup for a faster response. (Control-G using Outlook Express) --
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:ul**************@TK2MSFTNGP09.phx.gbl... Here is a snippet of my code behind class:
public class WebForm1 : Page { public string Hello() { return "Hello"; } }
From my asp page I have a <script> tag mixed within my html that looks like this:
<script runat=server> string x = Hello(); </script>
With this code I get this error:
CS0120: An object reference is required for the nonstatic field, method, or property 'Web1.WebForm1.Hello()'
This indicates I am not using the correct syntax for calling
code-behind. Any idea what I'm doing wrong? How do I get an instance of my page
object from within the script tag?
-Brett-
"Felbrigg" <so*****@microsoft.com> wrote in message news:u2**************@TK2MSFTNGP11.phx.gbl... Does your method have a return type? Does it return anything? If it does, does your line in the <Script> handle a retuned value. Are you using
c# or vb? You say the method is inherited and its public, is the pages class public?
"Brett Robichaud" <br************@nospam.yahoo.com> wrote in message news:e%****************@TK2MSFTNGP10.phx.gbl... > I understand how code-behind can handle events for a page, but can I call a > code-behind method from within a <script> tag in my ASP.Net page, or > can I > only call methods defined in other <script> sections? I can't seem
to > figure out the syntax for for calling code-behind directly. The
method is > within the class my page inherits from and is public, but when I try
to call > it from my page I get this error: > > CS1520: Class, struct, or interface method must have a return type > > What am I missing here? > > -Brett- > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andre |
last post by:
Hi,
I need to fetch a value in an Access db, so i use a form to pass the
parameter for the SQL statement fromVB client to ASP. After the submit line
in VBscript, i expect the value in order to...
|
by: Jean-Luc Gyger |
last post by:
Hello,
I have on a html page an applet. A javascript function call one function of
this applet. It works with IE but not with Mozilla or Netscape. I obtain
the following error on the java-plugin...
|
by: Sergio |
last post by:
<HTML>
<!- I need to write code that saves contents of the following form as
MyForm.txt(only Last_Name,First_Name) into directory
c:\MyPATH\MyForm.txt or into cookies directory.
-->...
|
by: Geoff |
last post by:
When trying to focus a field in Firefox, I get the following error:
Error: " nsresult: "0x8057001e
(NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
|
by: BookerW |
last post by:
Ok, here is the situation. I have some vb code that was upgraded to the
earliest asp, I believe. When i run this snippet of code below on my local
xp box with iis and visual studio 2003...
|
by: Booker Washington |
last post by:
ORIGINAL POST BELOW.. this is an addendum.... read from THE ORIGINAL
POST first and below... andthen come back up to this section
now upon further reading, i can provide some more...
|
by: David Purton |
last post by:
Hi,
I have some ASP code to stream a binary file. It works well and looks
something like the original ASP code shown below.
I'm experimenting in creating ZIP files on the fly and am trying to...
|
by: holger.gubbels |
last post by:
Hi ng,
I created a library in csharp which should by called by visual basic
script. The library is a proxy which provides access to a server using
dotnet-remoting features - but this is not...
|
by: CADD |
last post by:
I've used http://www.bloglines.com to add RSS feeds to my sites there
and setup javascript in my website to search bloglines for the input
term.
The code below works perfect, but I have 1 minor...
|
by: roshina |
last post by:
Hi
Iam facing a problem in my project, developing a web site for online shopping in ASP on windows XP using IIS server.
All the validations are ok but the new password is not upadated in the data...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |