473,383 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Getting to the ClientScript object from another C# Class

I want to create a C# class where I'll have a bunch of static functions which
will use the ClientScript object to dump out some JavaScript dynamically.

But I can't figure out how to get a hold of the "ClientScript" object in
those other classes. I guess it's that I have to get the current Page object
and work down to the Page's ClientScript object. But I don't know how to do
that either. I tried HttpContext.Current... but that doesn't get me to the
Page or the ClientScript object.

So how to I get a hold of the Page object from another class?

Alex
May 2 '06 #1
2 4833
Could you pass the Page object into your method as an argument?

- Steve

"Alex Maghen" wrote:
I want to create a C# class where I'll have a bunch of static functions which
will use the ClientScript object to dump out some JavaScript dynamically.

But I can't figure out how to get a hold of the "ClientScript" object in
those other classes. I guess it's that I have to get the current Page object
and work down to the Page's ClientScript object. But I don't know how to do
that either. I tried HttpContext.Current... but that doesn't get me to the
Page or the ClientScript object.

So how to I get a hold of the Page object from another class?

Alex

May 2 '06 #2
Hi Alex,

As for the ClientScript property, it is specific to the Page class, and as
for the HttpContext, it could be established for different httphandlers,
not only Page, but also other general httphandlers, that's why it doesn't
expose a Page property. However, we still could use the
HttpContext.Handler property to access the current request's processing
handler instance, if the request is a page request, the handler is just the
page instance. e.g:

Page page = HttpContext.Current.Handler as Page;

if (page != null)
{
page.ClientScript.RegisterStartupScript(page.GetTy pe(),
"msgbox", "alert('hello.');", true);
}

In addition, if the utility class is mostly used directly in page code, I
suggest you consider Steve's suggestion on passing the page instance as
input parameter of the utility functions.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 2 '06 #3

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

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
12
by: Sunny | last post by:
Hi All, I have a serious issue regarding classes scope and visibility. In my application, i have a class name "TextFile", and also a few other classes like "TotalWords", "TotalLines" and etc..,...
7
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am...
9
by: C | last post by:
Hi, On a click event of a button I do some validation. If my validation is unsuccessful I display an alert to the user as below. string message = "This is a test alert.";...
1
by: manfred | last post by:
Hi Has anyone a definition of the parametervalues and properties for a clientscript? MyName(source, args) I know: args.Value args.IsValid and whats the rest???
4
by: Jon Paal | last post by:
"Page.Clientscript" does not compile in assembly, with the error message "Reference to a non-shared member requires an object reference". ... what reference is it looking for ?????? class...
3
by: Stan SR | last post by:
Hi, I need to place some javascript code at the end of my aspx page. How can I do that using the ClientScript.RegisterClientScriptBlock ? Thanks Stan
2
by: verci | last post by:
Hi guys, I'm using asp.net 2.0, can anybody send me some complete examples on using ClientScript.RegisterClientScriptInclude and ClientScript.RegisterClientScriptSource, for registering an...
9
by: Dariusz Tomoń | last post by:
Hello, I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly from i.e. default.aspx.cs code but from a class belonging to DLL, which is referred in my project. The code...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.