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 5352
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.c om> wrote in message
news:e%******** ********@TK2MSF TNGP10.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*****@micros oft.com> wrote in message
news:u2******** ******@TK2MSFTN GP11.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.c om> wrote in message news:e%******** ********@TK2MSF TNGP10.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*****@micros oft.com> wrote in message
news:u2******** ******@TK2MSFTN GP11.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.c om> wrote in message news:e%******** ********@TK2MSF TNGP10.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.c om> wrote in message
news:e#******** ******@TK2MSFTN GP10.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.P age, 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.c om> wrote in message
news:e#******** ******@TK2MSFTN GP10.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.P age.
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******** ******@TK2MSFTN GP09.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.P age, 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.c om> wrote in message news:e#******** ******@TK2MSFTN GP10.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.c om> wrote in message
news:ul******** ******@TK2MSFTN GP09.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*****@micros oft.com> wrote in message news:u2******** ******@TK2MSFTN GP11.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.c om> wrote in message news:e%******** ********@TK2MSF TNGP10.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" <chrisjATmvpsDO TorgNOSPAM> wrote in message
news:uq******** *****@tk2msftng p13.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.c om> wrote in message news:ul******** ******@TK2MSFTN GP09.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*****@micros oft.com> wrote in message news:u2******** ******@TK2MSFTN GP11.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.c om> wrote in message news:e%******** ********@TK2MSF TNGP10.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 test it and go further in
VBscript. But my problem is when clicking on the button, that the VB code
doesn't wait to get that value and continues directly, so the a=<%=totd%>
line give 0 in stead of the real value. If i click a second time, i get...
|
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 consol:
sun.plugin.liveconnect.OriginNotAllowedException: Javascript is not form the
same origin as je java code ...
This is my html code:
|
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.
-->
<HEAD><TITLE>Insert Your data</TITLE>
<SCRIPT>
/*
Here javascript code
*/
|
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 ::
file:///C:/Documents%20and%20Settings/Edd/Desktop/test.html :: valText
:: line 24" data: no]
Source File: file:///C:/Documents%20and%20Settings/Edd/Desktop/test.html
Line: 24
Anyone have any ideas as to why this is happening?
|
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 installed, it runs just fine... when i
run it on my w2k3 box with iis and asp.net 1.1 and 2.0 installed, but only
1.1 active now because of the aspnet_regiis -i command that was run in the
v1.1.4 folder, i get the error below the code:
Code
<%@...
| |
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 context.......
Here is what my global.asax file contains
<%@ Application Codebehind="Global.asax.vb" Inherits="GT.Global" %>
below is some of the code from the default.aspx file. My global.asax
|
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 come
up with good ways of streaming binary files using ASP.NET, but I'm
having performance issue. The new ASP.NET code is also shown below. The
performance of this is *terrible*. I get less than 200 KB/s across a
LAN. The original code gives a...
|
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 important.
The library offers user defined data types, which are used by the proxy
interface - all of them created by using a factory.
Here is the visual basic code:
|
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 issue, hopefully
someone more family with javascript can help me out with.
1) the variables do not reset, so any future searches return the same
previous returned link, unless i clear settings/cookies.
|
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 base and also showing a error page.
the operating system we used is Windows XP,
the source code is ASP,
front end we used - HTML and
javascript and vb script for validations.
the inputs we used are :
old pasword :
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |