 |
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
|
|
|

July 22nd, 2009, 05:57 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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:
|
|

July 22nd, 2009, 07:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

July 22nd, 2009, 07:36 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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..
|

July 22nd, 2009, 11:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

July 23rd, 2009, 01:09 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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..
|

July 23rd, 2009, 03:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

July 27th, 2009, 07:17 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
sad
dhfhfdhfshfkls
fdsfsfsdfs
fsdfdafs
Quote:
Originally Posted by Imar
Yes, make My static as well.
You can use HttpContext.Current to get at the Server class....
Cheers,
Imar
|
|

July 27th, 2009, 08:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |