Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2009, 05:57 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: Hardwar, Uttranchal, India.
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Client calling server side

hello Friend,

I am writing this code to call server side function from the client script but when the compiler comiing to the line which is wirtten in Red Forecolor, compiler not reading it...I have to create a txt file inside the MyMethod function how can i do this ?

Please Help here.



[System.Web.Services.WebMethod]
public static string MyMethod(string Name)
{
_Default D = new _Default();
D.My(Name);
return Name + ", ajx call string";
}
void My(string FileName)
{
string MyPath = Server.MapPath(Server.MapPath("~/App_Data/"));
FileInfo F1 = new FileInfo(MyPath + FileName + ".txt");
F1.Create();
}


cheers!!
__________________
DPK..
The Following User Says Thank You to dpkbahuguna For This Useful Post:
anujrathi (July 27th, 2009)
 
Old July 22nd, 2009, 07:21 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there

Why are you calling MapPath twice? You only need it once...

And why are you creating a new _Default page instance? The whole idea behind static methods is that you can call them without an instance. I'd make My static as well (and rename it to something more logical......)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 22nd, 2009, 07:36 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: Hardwar, Uttranchal, India.
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default client calling server side

that was my silly mistake i did not take glance on it ....that was by mistake ....and as u asked I am making _Default class object becos without that I am not able to get that method inside the Static MyMethod() method...but Now it is running fine...
Is there any other way too to call that method without making any instance of My() function method.

one thing more friend cant i use "Server" class inside the Static Function ...?



Thanks cheers :)
__________________
DPK..

Last edited by dpkbahuguna; July 22nd, 2009 at 08:31 AM..
 
Old July 22nd, 2009, 11:59 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Is there any other way too to call that method without making any instance of My() function method
Yes, make My static as well.

You can use HttpContext.Current to get at the Server class....

Cheers,


Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 23rd, 2009, 01:09 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: Hardwar, Uttranchal, India.
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default client calling server side

Thanks for ur reply Imar,

I am confused to take static...as the static variable which always gets one for all the clients..I mean to say suppose I have one static variable in my site suppose it is
static int a = 0;

and Two clients opened my page 1st client puts value "10" to it..and at the just after 2nd client puts "20" so that value overwrites the other client value too. so now value will be 20 for all the clients. Is it write ?

if yes then is it not risky to use static function or variable in websites until u dont have any particular requirement.

thanks!!
__________________
DPK..
 
Old July 23rd, 2009, 03:42 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Yes, statics are used and shared throughout the application. However, when you write static methods that don't rely on instance state you're OK. In the case of HttpContext.Current you get access to a *current* instance which only applies to the current request. This means whatever you use there is request specific (stuff like Session, QueryString etc are all available)...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 27th, 2009, 07:17 AM
Authorized User
Points: 375, Level: 6
Points: 375, Level: 6 Points: 375, Level: 6 Points: 375, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2006
Location: New Delhi,India.
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi
Default sad

dhfhfdhfshfkls
fdsfsfsdfs
fsdfdafs


Quote:
Originally Posted by Imar View Post
Yes, make My static as well.

You can use HttpContext.Current to get at the Server class....

Cheers,


Imar
 
Old July 27th, 2009, 08:01 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Posted by anujrathi:

dhfhfdhfshfkls
fdsfsfsdfs
fsdfdafs

Please don't post useless messages like this. You're only wasting other people's resources and time....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
Firing server side events at client side codes mehdi62b ASP.NET 1.0 and 1.1 Basics 6 May 18th, 2005 09:11 AM
sharing a server-side variable with client-side pigtail Javascript How-To 6 November 4th, 2004 02:01 AM
Two Client Side vs Server Side issues Milo Classic ASP Professional 5 May 25th, 2004 02:47 PM
Accessing Server Side Data on Client Side steve456 Classic ASP Professional 3 October 15th, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.