473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using page-object in .cs-file

I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it works");
</script>";
Page.RegisterStartupScript("frreload", script);
}

If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to re-use
this method in other aspx-pages, I get an error while compiling the file: "
error CS0120: An object reference is required for the nonstatic filed,
method, or property 'System.Web.UI.Page.RegisterStartupScript(string,
string)'

Where can I get the current "page-object", so that I can use the function
RegisterStartupScript ?

Thanks for help.
Nov 19 '05 #1
5 1225
I believe your only option is to pass the page in as a parameters
public static void justdoit(Page page){
string script = "...";
pageRegisterStartupScript("fireload", script);
}

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message
news:uY**************@TK2MSFTNGP14.phx.gbl...
I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it works");
</script>";
Page.RegisterStartupScript("frreload", script);
}

If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to re-use this method in other aspx-pages, I get an error while compiling the file: " error CS0120: An object reference is required for the nonstatic filed,
method, or property 'System.Web.UI.Page.RegisterStartupScript(string,
string)'

Where can I get the current "page-object", so that I can use the function
RegisterStartupScript ?

Thanks for help.

Nov 19 '05 #2
It helps to think in terms of classes rather than files. They are only files
as far as you're concerned, and only when you're writing code. To the app.,
they are classes, and they behave like classes. Sometimes all it takes to
see something clearly is to think of it in the right way.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message
news:uY**************@TK2MSFTNGP14.phx.gbl...
I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it works");
</script>";
Page.RegisterStartupScript("frreload", script);
}

If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to
re-use this method in other aspx-pages, I get an error while compiling the
file: " error CS0120: An object reference is required for the nonstatic
filed, method, or property
'System.Web.UI.Page.RegisterStartupScript(string, string)'

Where can I get the current "page-object", so that I can use the function
RegisterStartupScript ?

Thanks for help.

Nov 19 '05 #3
Hello Alexander,

public static void JustDoIt()
{
string script = @"
<script language='javascript'>
alert('it works');
</script>";

Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.RegisterStartupScript("frreload", script);
}
}

--
Matt Berther
http://www.mattberther.com
I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it
works");
</script>";
Page.RegisterStartupScript("frreload", script);
}
If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to
re-use this method in other aspx-pages, I get an error while compiling
the file: " error CS0120: An object reference is required for the
nonstatic filed, method, or property
'System.Web.UI.Page.RegisterStartupScript(string, string)'

Where can I get the current "page-object", so that I can use the
function RegisterStartupScript ?

Thanks for help.


Nov 19 '05 #4
thank you very much
"Matt Berther" <mb******@hotmail.com> schrieb im Newsbeitrag
news:22***************************@news.microsoft. com...
Hello Alexander,

public static void JustDoIt()
{
string script = @"
<script language='javascript'>
alert('it works');
</script>";

Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.RegisterStartupScript("frreload", script);
} }

--
Matt Berther
http://www.mattberther.com
I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it
works");
</script>";
Page.RegisterStartupScript("frreload", script);
}
If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to
re-use this method in other aspx-pages, I get an error while compiling
the file: " error CS0120: An object reference is required for the
nonstatic filed, method, or property
'System.Web.UI.Page.RegisterStartupScript(string, string)'

Where can I get the current "page-object", so that I can use the
function RegisterStartupScript ?

Thanks for help.


Nov 19 '05 #5
Well, you learn something every day, thx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message
news:eP**************@TK2MSFTNGP15.phx.gbl...
thank you very much
"Matt Berther" <mb******@hotmail.com> schrieb im Newsbeitrag
news:22***************************@news.microsoft. com...
Hello Alexander,

public static void JustDoIt()
{
string script = @"
<script language='javascript'>
alert('it works');
</script>";

Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.RegisterStartupScript("frreload", script);
} }

--
Matt Berther
http://www.mattberther.com
I have a file "file1.cs" with a method:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public static void justdoit()
{
string script = "<script language=\"JavaScript\"> alert("it
works");
</script>";
Page.RegisterStartupScript("frreload", script);
}
If I use this method directly in an aspx-page it works.... But now the
problem: If I write this Method in a seperate file, because I want to
re-use this method in other aspx-pages, I get an error while compiling
the file: " error CS0120: An object reference is required for the
nonstatic filed, method, or property
'System.Web.UI.Page.RegisterStartupScript(string, string)'

Where can I get the current "page-object", so that I can use the
function RegisterStartupScript ?

Thanks for help.



Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Dave Smithz | last post by:
Hi, In summary: I want to a form to submit information via a HTTP POST, however, when using Internet Explorer I want to be able to use the back button and all the information retained....
2
by: Glenn | last post by:
Is there any way to partially refresh a web page on each request? I have a search page that needs to refresh the number of results with each change in the form elements. Since there are so many...
1
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it...
8
by: Ed Jay | last post by:
I want to use history.go() to navigate between my previously loaded pages. I'm looking for a way to trigger a function call when a page is accessed using history.go(). Is there an event generated?...
8
by: Taras_96 | last post by:
Hi everyone, We' ve come to the conclusion that we wish the user to be directed to an error page if javascript is disabled <enter comment about how a webpage shouldn't rely on javascript here :)...
4
by: sirumalla.srinivas | last post by:
Hi, I have link to the various documents which is stored on the server. When ever user click on any link, the respective document should be opened. Here what i need is to have all the links on...
3
by: =?Utf-8?B?Q2hhZCBTY2hhcmY=?= | last post by:
I have a 3 page ASP.NET web application that is using an asp:Wizard control on the main page. There is no authentication (completely open) and all processesing is done on this single page. I have a...
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
4
by: James | last post by:
Hello everyone, While loading a page (http://www.edmonton.ca/portal/server.pt?space=CommunityPage&control=SetCommunity&CommunityID=239) into a webbrowser control I use invokemember on the...
0
by: Abubakar | last post by:
Hi, I've been assigned to work on a asp.net page that when viewed on internet, renders very slowly and its hosted on a client machine which is a p4 3.0ghz HT, with 2 gb ram running windows...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...
0
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.