|
Hi
I need advice on which way to proceed. I have two scenarios
Case 1:
I have an aspx page which reads from a Xml file using XmlDcoument object, process it and stores the data in a datatable. The datatable may contain from 10 to max 1000 rows depending on the Xml file.
I am using couple of update panels and hence there are frequent postbacks expected. My question is which would be better performancewise :
1. Store the datatable in viewstate / Cache / Session OR
2, Read the data from Xml file and build the datatable during each postback.
Pls note that the xml file is very big and the processing involves multiple loops before storing the data in the required format in the datatable.
Case 2:
Here is a datatable whose rows are created based on the user input during partialpostbacks. The data should be retained until the final submit button is pressed. What would be the best way to achieve it.
Store the datatable in viewstate Or Cache Or Session or declaring it as static.
Please note that both the datatables are just pagelevel and multiple users may access it. I want each user to have their own copy of the datatable.
any guidance on which way to choose would be appreciated.
thanks
Kit.
|
|
|
|
|
Well, you must first be aware of the differences of functionalities between session, asp Cache and viewstates. It is not only about memory.
For example:
You load your page. You store some data in ViewState["x"].
You load another page. You also store some data in ViewState["x"], but it is a different data.
No problem will be caused, as ViewState is linked to the calling page. If you open a new web-browser in the same page (Control+N) as soon as you do anything different, each page (the old and the new) will have different view-states, so the old-page will not display the new data if you press F5, for example.
Session. If you put information named "X" in session, every page will share the same information. If you update information X in one page, it will also change the X visible in another page, which may not be wanted. But, of course, it will not affect other users, as they will have other sessions.
Asp Cache. The cached item will be shared among all users. This is rarelly what is needed.
The biggest problem of ViewState is that it is sent to the client. So, many times reprocessing the item is better (faster) than sending it to the client and receiving it back. But, I must say I have a solution for this.
Look at my article:
Pfz.Caching - ViewIds instead of ViewStates[^]
Using it, the view-state will works as always in terms of being exclusive to a page, a Control+N will not corrupt it, but it will be kept in the server memory and/or disk, without being sent to the client. Probably the easiest and faster solution considering general cases.
|
|
|
|
|
Thanks for the reply, Paulo.
I think I should explain my situation a bit more in detail. I am working on the reporting stuff - that produces a chart. The datatable stores the different data entered by the user that should appear in the chart. For someother reasons there are a couple of partial postbacks before the chart is generated. I need to hold the user specifications until the actual chart is generated.
I am really fine with the Ctrl+N problem When the user presses Ctrl+N to open another instance of the same page, it might be like he wants to see two different formats of report. In that case I am glad if the viewstate values of old and new page remains different. thats what I exactly want.
I could achieve this behaviour with viewstate and also by declaring the datatable as static at page level. eg
static DataTable dt1 = new DataTable();
Even with declaring dt1 as static, Ctrl+N does not affect the old page. Old and new page has their own copy of the dt1 which is what i want.
But I wonder which is efficient and is there anyother better way of doing it. (Just to remind you that this datatable is used only in the single page)
|
|
|
|
|
The different copies are only achieved with ViewState. Using session or cache, except that you give different names, will not achieve different copies. That's why I say you must use ViewState.
The only problem with normal viewstate is that it is sent to the client and so, if the data is large, it could make the page load really slowly. That's why I talked about my ViewState solution.
So, go for the ViewState.
|
|
|
|
|
Many thanks for the reply Paulo.
But I am able to reproduce the behaviour by declaring the datatable as static at page level. I have always thought that a single copy of the static variable is shared by all the users. I guess i should start a new thread on this. anyways, many thanks for your reply and the amazing article.
|
|
|
|
|
Each static variable is unique for the entire application. All users, sessions and thread will share the same value.
If the variable is marked with ThreadStatic, then it is unique for the thread but, still, for that thread any object (or page) referencing it will reference the same value (as one thread can process many page requests)
|
|
|
|
|
Hi,
how can i found that first index value in a string is char or numeric.
Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this.
Ex: String str = "CodeProject";
G. Satish
|
|
|
|
|
public static bool IsFirstCharNumber(string str) {
if (string.IsNullOrEmpty(str))
return false;
int i = (int)str[0];
return (i < 58) && (i > 47);
}
|
|
|
|
|
public bool IsFirstCharDigit(string szYourstring)
{
if((szYourString != null) && (szYourString.Length > 0))
return char.IsDigit(szYourString.Chars(0));
return false;
}
Greetings
Covean
|
|
|
|
|
Thanks for the 1 vote!
So I found an error in my code.
But I think 1 is too hard!
public static bool IsFirstCharDigit(string szYourString)
{
if((szYourString != null) && (szYourString.Length > 0))
return char.IsDigit(szYourString[0]);
return false;
}
or
public static bool IsFirstCharDigit(string szYourString)
{
if(!string.IsNullOrEmpty(szYourString))
return char.IsDigit(szYourString[0]);
return false;
}
Greetings
Covean
|
|
|
|
|
Good Day
I have posted this question before , i cant find it to continue from it. Let me start from Scratch because i did not find a Solution to this problem.
in my page am using a Treeview Control show like this
http://www.vuyiswamaseko.com/public/Wrong_Display.JPG[^]
and am loading data in SQL like this
http://www.vuyiswamaseko.com/public/Query_Wrong_Display.JPG[^]
and my code behind for loading the control looks like this
public void PopulateTreeFromCurr(int currID)
{
IEnumerable result = CurrStructDataSource.Select(DataSourceSelectArguments.Empty);
int Parent, Child;
CurriculumTreeView.Nodes.Clear();
ArrayList CurrNodes = new ArrayList();
if (result != null)
{
foreach (System.Data.DataRowView row in result)
{
TreeNode newnode = new TreeNode(row["Description"].ToString(), row["NodeID"].ToString());
CurrNodes.Add(newnode);
if (row["refParent"].ToString() == "")
{
}
else
{
Parent = Convert.ToInt32(row["refParent"]);
Child = Convert.ToInt32(row["ID"]);
TreeNode ParentNode = new TreeNode();
TreeNode ChildNode = new TreeNode();
ParentNode = (TreeNode)CurrNodes[Parent];
ChildNode = (TreeNode)CurrNodes[Child];
ParentNode.ChildNodes.Add(ChildNode);
CurrNodes[Parent] = ParentNode;
}
}
if (CurrNodes.Count > 0)
{
CurriculumTreeView.Nodes.Add((TreeNode)CurrNodes[0]);
CurriculumTreeView.ExpandAll();
}
}
}
This above will show me results in this Manner in my application
http://www.vuyiswamaseko.com/public/Wrong_Display.JPG[^]
but now i want the Display to be like this
http://www.vuyiswamaseko.com/public/Correct_Display.JPG[^]
and i have changed my Query so that it gives me the Correct results from the SQL and i changed it to this
http://www.vuyiswamaseko.com/public/Query_Right_Display.JPG[^]
and the above Results in SQl they are Correct , but now when i run it, in the Application i get an Error
http://www.vuyiswamaseko.com/public/Received_Error.JPG[^]
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I'm facing a problem. I'm giving different image path in my project. The path i'm giving is in project folder, it's in another location. i'm using datalist. The file path is coming correct but image is not showing.
Please give me solution. Its urgent.
Thnax..
krishna veer singh
|
|
|
|
|
Always place virtual path to the image. A path which can directly called to the server to get the image.
No client can see an image if the image is somewhere other than to valid virtual path..
Also it is better to use Relative path, relative to the root of the virtual directory.
|
|
|
|
|
Hi,
Right click on your image and copy image address and paste this on browser directly, If your image is display then your path is correct, otherwise use relative path.
Farogh Haider
Web developer
|
|
|
|
|
try to do As Abhi suggested..!
krishnaveer wrote: m giving different image path in my project.
Copy the image from tht path and store it in your localserverfolder and access tht image..!
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
I have copied the path and paste it into window explorer, its showing the image. But the same url is not working when m using it in project.
krishna veer singh
|
|
|
|
|
You Misunderstood my friend..!
i told you to copy the image from local server drive programatically and store it in your server.MapPath as you are doing for file upload control
and now you access the image..!
AFAIK You cant access the image directly from the local drive..!
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
Hi,
I am working on a Asp.net application. In this, on a button click I need to display a popup with a listbox control. After selecting the values in this listbox they should be add to the grid or displayed on the starting page. I think we can use model popup here. Please let me know how to use this or any other solution.
If anyone have any idea to do this please reply me.
Thanks in advance.
|
|
|
|
|
Nekkantidivya wrote: I think we can use model popup here.
Yes you can use ModalPopUp[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
Hi ,
Is there any way to upload a file using drag and drop to browser ?......Could you please help me ?
with warm regards
|
|
|
|
|
I think you can do this using an ActiveX (IE only). Or search for some third party controls that allow you to do this.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
No.... You cant...
Fileuploader should point the file by opening OpenFileDialog. Even setting Value of input type="file" doesnt actually get the pointer to the disk file in the client computer.
|
|
|
|
|
yeah ,
is there any Jquery plugins for that ?
|
|
|
|
|
Sorry my friend..
If JQuery can do that .. .We can also do that.. If there is no option, how does JQuery do...
|
|
|
|
|
Hi all,
I need to show the Country DDL first, if i select the country then it has to fill the states in and after that city..
if i have a database i can do..
but its very difficult to enter all those in the database..
and i searched in web, i saw one website that they are providing db but its chargable.
is there any methods in asp side, so that we can access and show?
help me, thanks in advacne..
|
|
|
|