can we store viewstate in masterpage?
-
can we store viewstate in masterpage. so that when a user tries to open a new tab, the id is fetched from the viewstate.
Everything Is Possible!
Suresh Dayma wrote:
can we store viewstate in masterpage.
I didn't get your question. What do you mean by store view state in master page. I would suggest you to have a qucik look into Beginner's Guide To View State [^]article, and let me know if you have any more issue.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Suresh Dayma wrote:
can we store viewstate in masterpage.
I didn't get your question. What do you mean by store view state in master page. I would suggest you to have a qucik look into Beginner's Guide To View State [^]article, and let me know if you have any more issue.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Thanks for your reply. ok, just take an example this is what i want in masterpage, i have created a label called 'customer name'. and fetched the customer name from the database and assigned it to the label. when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database. (Assume there is a single master page and multipe content pages.)
Everything Is Possible!
-
Thanks for your reply. ok, just take an example this is what i want in masterpage, i have created a label called 'customer name'. and fetched the customer name from the database and assigned it to the label. when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database. (Assume there is a single master page and multipe content pages.)
Everything Is Possible!
Suresh Dayma wrote:
when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.
For that you need to use
Session
insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse//Storing UserName in Session Session\["CustomerName"\] = dbUserName;
Now, let see how we can retrieve values from Session Collapse
//Check weather session variable null or not
if (Session["CustomerName"] != null)
{
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
}
else
{
//Do Something else
}Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Suresh Dayma wrote:
when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.
For that you need to use
Session
insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse//Storing UserName in Session Session\["CustomerName"\] = dbUserName;
Now, let see how we can retrieve values from Session Collapse
//Check weather session variable null or not
if (Session["CustomerName"] != null)
{
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
}
else
{
//Do Something else
}Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.
Everything Is Possible!
-
Suresh Dayma wrote:
when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.
For that you need to use
Session
insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site. Following code is used for storing a value to session Collapse//Storing UserName in Session Session\["CustomerName"\] = dbUserName;
Now, let see how we can retrieve values from Session Collapse
//Check weather session variable null or not
if (Session["CustomerName"] != null)
{
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
}
else
{
//Do Something else
}Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Abhijit Jana wrote:
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
This won't compile. Adding a
string
andobject
is invalid. You needToString()
.lblWelcome.Text = "Welcome : " + Session["CustomerName"].ToString();
:)
Best wishes, Navaneeth
-
Abhijit Jana wrote:
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
This won't compile. Adding a
string
andobject
is invalid. You needToString()
.lblWelcome.Text = "Welcome : " + Session["CustomerName"].ToString();
:)
Best wishes, Navaneeth
My Bad. Thanks for correcting me !!:thumbsup:
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.
Everything Is Possible!
Suresh Dayma wrote:
but when the user tries to open it in a new tab then this does not work.
Are you talking about browser new Tab ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Currently, i have used the sessions to store this. but when the user tries to open it in a new tab then this does not work. Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then it will overwrite the customer details. so it does not make sense to store customer details in Session.
Everything Is Possible!
I think you need to use Database. Once it is modified, just store it into database and from any other tab / in any other browser in the world, it will be shown updated. No need for ViewState / Session etc. ;) If this is your temporary storage, u might use temporary database tables as well. :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
My Bad. Thanks for correcting me !!:thumbsup:
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
is there any workaround for this issue?
Everything Is Possible!
-
Suresh Dayma wrote:
but when the user tries to open it in a new tab then this does not work.
Are you talking about browser new Tab ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
yes, you are correct
Everything Is Possible!
-
is there any workaround for this issue?
Everything Is Possible!
I have already suggested one workaround I guess... See, Viewstate is stored in page (So Rejected) Session is stored in server but for a single session (Rejected as IE opens a new session for each tab) Application is User Independent. Cookie ... Domain specific. Its possible to use this, But I dont like it as client can easily clear that. Also if is browser specific. Say one person opens the same site once in IE another in Mozilla.. Cookies will be different, (Hence Rejected) So there is only one option. Just change it globally, so that anywhere the change is reflected. Hope you got it. cheers. :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
I have already suggested one workaround I guess... See, Viewstate is stored in page (So Rejected) Session is stored in server but for a single session (Rejected as IE opens a new session for each tab) Application is User Independent. Cookie ... Domain specific. Its possible to use this, But I dont like it as client can easily clear that. Also if is browser specific. Say one person opens the same site once in IE another in Mozilla.. Cookies will be different, (Hence Rejected) So there is only one option. Just change it globally, so that anywhere the change is reflected. Hope you got it. cheers. :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptI really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?
Everything Is Possible!
-
I really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?
Everything Is Possible!
You are most welcome.. Dont forget to click "good answer" if it actually helped you and also to mark that as answer for future reference. ;)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
I think you need to use Database. Once it is modified, just store it into database and from any other tab / in any other browser in the world, it will be shown updated. No need for ViewState / Session etc. ;) If this is your temporary storage, u might use temporary database tables as well. :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptI dont think this is the solution.
Everything Is Possible!
-
Suresh Dayma wrote:
but when the user tries to open it in a new tab then this does not work.
Are you talking about browser new Tab ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Hi abhijit, is there any work around for this issue?
Everything Is Possible!
-
I dont think this is the solution.
Everything Is Possible!
Then please let me clear this. If you open a new browser tab, it doesnt allow you to access any data from other tab because of security issues. Mozilla retains its session data for every tab. So in case of mozilla, it do work in multiple tabs. But in IE it doesnt. One thing that you might use is Cookie. If you call a server for same domain, you can use it to send data. Say you call www.xyz.com it can create cookie data in browser based on the address. So that after a certain while or at the same instant if a new browser is opened and same address is navigated, you will find the data from cookie easily. Say you write like this :
Response.Cookies["txtCookie"].Value = this.txtcookie.Text; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1);
Now from another browser instance if you callstring txtCookie = Request.Cookies["txtCookie"].Value;
it will give you appropriate data. By this way you can send data to different browser instances. :cool:Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
I really appreciate your help. but still i have to make changes in all the content pages(i.e. globally) right. Isn't there way by which i have to make changes in the masterpage itself?
Everything Is Possible!
No you can do that in Masterpage as well. Just write your code in masterpage page_load and it will work perfectly. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
No you can do that in Masterpage as well. Just write your code in masterpage page_load and it will work perfectly. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptNo dear, it does not work.
Everything Is Possible!
-
No dear, it does not work.
Everything Is Possible!
Tell me what you did so far. Just do like this : write Response.Cookies["txtCookie"].Value = myid; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1); inside your masterpage, and it will be accessible to any page that inherits masterpage (also normal pages) I have done this a lot of times, and it worked perfectly... To request the cookie use Request.Cookies["txtCookie"] :-D
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
Tell me what you did so far. Just do like this : write Response.Cookies["txtCookie"].Value = myid; Response.Cookies["txtCookie"].Expires = DateTime.Now.AddDays(1); inside your masterpage, and it will be accessible to any page that inherits masterpage (also normal pages) I have done this a lot of times, and it worked perfectly... To request the cookie use Request.Cookies["txtCookie"] :-D
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascriptbut my id keeps on changing depending on the no. of tabs opened(Firefox). And Each tab has to maintain different ids(customerId for instance). Example I have a gridview having multiple customers. if i open multiple customer details on multiple tabs then there should be different customerid assigned to different pages. In case if i use cookie then it will store a single customerid and when the page makes a request then this id will be assigned to all the pages. I dont want to do like this. I dont think, this is a solution(i.e. Cookie)
Everything Is Possible!