|
Shivan Nandan wrote: The problem is that when more than one user access this page and modifies the variable a, all the users gets the new value for a,
i.e., they loose the value what they had set for a. They get the value that is been set by the last user.
That is the correct functionality. ASP.NET applications are multi-user applications. static variables are global for the entire application. If you set it to some value then all users will see that value.
Shivan Nandan wrote: If I remove 'Static' from its declaration, then its value is not available to other functions.
Incorrect. Its value is available to the methods in the class. This time however, the value only lasts as long as the object it is in lasts (in this case the object is the one representing your page).
Shivan Nandan wrote: How to solve this problem.
Looking at your sample code, you expect the value to hang around for postbacks. That isn't going to happen. The page object (along with your variable) will exist for as long as it takes to process and render the page. The page object is them discarded (along with your variable).
So, basically, you need some mechanism to store the value between postbacks. You can store the value in the page itself (a hidden field, or add it to the viewstate). You could store it in the session. You could create your own mechanism. It is up to you.
Ultimately, you need ot read a book on how ASP.NET works, and especially how the page lifecycle works as this leaky abstraction trips up many people. In other words HTTP is stateless, but ASP.NET tries to provide a stateful framework, and sometimes it just doesn't work they way you'd expect. So you have to go and read some stuff about the page lifecycle to understand what is going on.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
Thank you very much for helping me...
Shivanandan C V
modified on Wednesday, June 10, 2009 4:17 AM
|
|
|
|
|
I am handling one project in asp.net.Now I want to update my sql database when anyone leave the domain. So I need to call a stored Procedure when user leave page. And I can do it very easily if user click on logout button. But the problem arises when anyone just close the browser (by clicking cross button) or when he navigate away to another page (typing another address in address bar). Some ppl said that this can be done with Ajax script. Anyone please provide some coding for this?
Regards,
Shimona
|
|
|
|
|
|
hey shimona 2,
The issue can be dealed with javascript, Please go through the following html code that captures the close button click event
<html>
<head>
<script language="javascript" type="text/javascript">
window.onbeforeunload = myunload;
function myunload()
{
alert('Window is closing!!');
}
</script>
</head>
<body>
</body>
</html>
Hope this helps
Regards
|
|
|
|
|
Hello everyone,
I am designing one simple application where i want to insert, update and delete a XML file using DataGrid and XmlDataSource. I am done with adding and deleting code, but one thing i am stuck with is i cannot view the updated or deleted data back to the grid view after the page gets post back when we click the add or delete button although i have check the xml file and the data gets added and deleted respectively.
I have tried with DataGrid1.DataBind() method but its not working. To add and delete data programatically i have to implement e.Cancel = true; in the DataGrid1_RowDeleting event(without this it won't work). please tell me a way to dynamically reflect the updated data back to the grid view
Waiting for a quick response. Thanks in advance
Regards
|
|
|
|
|
Where did you load the data? Can you please put the GridView Data Load Code ? Did you check the Page.ISPostback while loading the data on gridview ?
|
|
|
|
|
Thanks for replying.
Actually i have used an XmlDataSource and set its DataFile property to the xml file and set the DataGird's DataSourceID property to the XmlDataSource. I have given the XPath rules to the grid view colomns to display the data.
Well m sure i have done some mistake but where i have done it i couldn't figure it out. Please help
Regards
|
|
|
|
|
hi..
even i am facing the same problem. can some one pls help me soon.
i have a XMLDataSource for which i mentioned the datafile to 'MyXml'.
In my page i have a textbox and a button 'add' for adding the text to the xml and display the same in the datagrid.
but wen i click that add button the data is getting updated in xml file and i can see that, but in the datagrid it is not getting updated.
pls help soon.thanx in advance.
|
|
|
|
|
Hi to all,
I need your assistance. Please help me on this.
I published my website but when I tried to browse, it is giving the following error:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 38: ASP.NET to identify an incoming user.
Line 39: -->
Line 40: <authentication mode="Windows">
Line 41:
Line 42: </authentication>
Source File: e:\inetpub\host134\vicinternational\vicinternational.vic.edu.au\www\vic\web.config Line: 40
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
what to do? PLease tell me. Its very urgent.
cheers,
sneha
|
|
|
|
|
sneha Choudhary wrote: I published my website but when I tried to browse, it is giving the following error:
After publishing the web site what you did? Did you create the Virtual Directory in IIS? Did you set the ASP.NET Framework version of the Virtual directory?
|
|
|
|
|
Hi,
Thanks for replying. Yes created a virtual directory in IIS.
And I am using Visual Studio 2008 and
ASP.NET Framework version of the Virtual Directory is 2.0.50727.
Am I doing right?
cheers,
sneha
|
|
|
|
|
sneha Choudhary wrote:
what to do? PLease tell me. Its very urgent.
It can't possibly be, because the mistake you've made is both far to elementary for this task to have been trusted to you, if it's urgent, and, if it was urgent, you'd have googled the error message and got your answer.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hello Sir,
I googled a lot but from there I got the idea to configure the site to IIS. I did that.But again getting the same error.
cheers,
sneha
|
|
|
|
|
In IIS Virtual Directory Properties, click "Create" for application name.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|
|
Hi,
I created the virtual directory but still giving the same error.
cheers,
sneha
|
|
|
|
|
It seems that you did not get me right. Just go to IIS Manager, choose your application and go to properties and check whether the application has been created or not. You can find a remove button if it was already created else you will find a create button. Also check whether your project directory contains multiple web.config file or not.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|
|
I did the same you have suggested and I found that "Remove" button. And I am not having a single web.config file.
Can you tell me one thing that I am using Visual Studio 2008 so what should be the version of asp.net in the virtual directory.
cheers,
sneha
|
|
|
|
|
sneha Choudhary wrote: . And I am not having a single web.config file.
Do you have multiple web.config at root level?
sneha Choudhary wrote: Can you tell me one thing that I am using Visual Studio 2008 so what should be the version of asp.net in the virtual directory.
It should be 2.0 .
|
|
|
|
|
it is showing 2.0.50727 in the asp.net tab in the virtual directory.
cheers,
sneha
|
|
|
|
|
I got the problem may be. Just go to ASP.NET tab and check whether ASP.NET 1.X is selected or not. If it is then change it to ASP.NET 2.X or greater. You will get the solution.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|
|
I Don't think so, because in her first post she said ASP.Net Version set to 2.x.x.x
|
|
|
|
|
sneha Choudhary wrote: I created the virtual directory but still giving the same error.
It seems Virtual Directory Still not created. Do as sannj suggested. Right Click on VD > Properties > In the Virtual Directory Tab There should be Create Button. Click on that, they try to access the site.
|
|
|
|
|
Firstly I opened the IIS then in the left pane there is a folder "web sites". Under this there is "Default Website". I right clicked on "Default Website" and selected new virtual directory.Then a wizard opened and successfully created a virtual directory named "vic". Now the "vic" is coming under the "Default Website". Then I right clicked the "vic" and then properties and I got a window named "vic properties" and in this there is virtual directory tab there is a label "application name" and in front there is a textbox and in it is showing "vic" and the there is remove button.
If I have done anything wrong please shout on me.
cheers,
sneha
|
|
|
|
|
I think you have perfectly configured the virtual directory. Check whether multiple web.config for the same project exists in the same parent directory or not. Check if your project has the same copy as a child folder in the root project directory. Refer the following figure:
Project A
>>>>>>Folder 1
>>>>>>Folder 2
>>>>>>Project A
Just check it.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|