Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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)
  #2 (permalink)  
Old July 22nd, 2009, 07:21 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
  #3 (permalink)  
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..
  #4 (permalink)  
Old July 22nd, 2009, 11:59 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
  #5 (permalink)  
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..
  #6 (permalink)  
Old July 23rd, 2009, 03:42 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
  #7 (permalink)  
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
  #8 (permalink)  
Old July 27th, 2009, 08:01 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.