I have three tabs (1,2,3) on my main page each tab contains a datagrid... when a user select a tab then leaves the main page and returns to that main page(without exiting browser) I need for the page to open with the tab last selected by that user so that they can pick up where they left off. No one can seem to help me with this issue....
My javascript (client side) code function is as follows:
<
asp:HiddenField ID="hdnNewPanel" runat="server" /> <script language="javascript" type="text/javascript">function SwitchPanels(newPanel)
{
if(newPanel == 1){
tdTasks.className='ptsSelectedLeftmostTab';tdNotices.className=
'ptsUnSelectedTab';tdQueries.className='ptsUnSelectedRightmostTab';taskDiv.className='ptsOpenDiv';
noticeDiv.className=
'ptsClosedDiv';queryDiv.className='ptsClosedDiv';hdnNewPanel = "1";}
else if(newPanel == 2){
tdTasks.className=
'ptsUnSelectedLeftmostTab';tdNotices.className='ptsSelectedTab';tdQueries.className='ptsUnSelectedRightmostTab';
taskDiv.className=
'ptsClosedDiv';noticeDiv.className='ptsOpenDiv';queryDiv.className=
'ptsClosedDiv'; hdnNewPanel = "2";}
else if(newPanel == 3){
tdTasks.className='ptsUnSelectedLeftmostTab';tdNotices.className=
'ptsUnSelectedTab';tdQueries.className='ptsSelectedRightmostTab';taskDiv.className='ptsClosedDiv';
noticeDiv.className=
'ptsClosedDiv';queryDiv.className='ptsOpenDiv'; hdnNewPanel = "3";}
}
</
script><script type="text/javascript">public int function getValue(newPanel){
string hdnNewPanel;
document.getElementById ('<% =hdnNewPanel.ClientID %>').value = hdnNewPanel;
}
</
script>What should my server side (code behind) be that would call the tab selection from client side hidden field and invoke it into main page when returning?
![]() |
0 |
![]() |
thea3100:
I have three tabs (1,2,3) on my main page each tab contains a datagrid... when a user select a tab then leaves the main page and returns to that main page(without exiting browser) I need for the page to open with the tab last selected by that user so that they can pick up where they left off. No one can seem to help me with this issue....
what do you mean by that
A fine is a tax for doing wrong. A tax is a fine for doing well.
__________________________________________________
Please remember to click “Mark as Answer” on the post that helps you.
![]() |
0 |
![]() |
Hi,
You are storing the current tab id in the hidden filed. In this case, if the user leaves the page and go for the other page, the value in hidden field would be lost. So next time when they come back to the screen, you would not be able to retain the tab's position.
Try to store the current tab position in the session value. Then always populate the tab's value from session.
Rajganesh
__________________________________________________
My Blog
If this post answers your question please mark it as Answered.
![]() |
0 |
![]() |
I tried using sessions before and couldn't get that to work, that is why I resorted to hidden field. Can you point me in the right direction with maybe some sample code perhaps? All I want it to do is keep the tab number selected into session for reuse while the session is still active. I'm not storing anything once the browser is closed. So if the user picks tab one, then leaves the main page to do something else, when or if they do return to the main page, tab one will still be selected. No one can seem to figure this out for me......
![]() |
0 |
![]() |
The only way that you could use Session state would be to do a PostBack, since Session state is ONLY available in the server-side code. The easy way is to create properties in the CodeBehind. Here is a simple example.
protected string YourVariableName
{
get
{
object sessionObject = this.Session["YourVariableName"];if ( sessionObject == null )
{
// Set to some default value
sessionObject = "";
}return (string)sessionObject;
}
set
{
this.Session["YourVariableName"] = value;
}
}protected void Page_Load(object sender, EventArgs e)
{
if ( this.IsPostBack )
{
YourVariableName = yourHiddenField.Value;
}
else
{
yourHiddenField.Value = YourVariableName;
}
}NC...
![]() |
0 |
![]() |
Thank you, now I'm getting The following error:
"the namespace '<global namespace>' already contains a definition for '?'
![]() |
0 |
![]() |
try using query string. if query string is not empty set the value to the default tab otherwise set it to the value in the query string. you can also use sessions. let me know if this does not work for you.
Vamsi Komarneni
Microsoft Certified Professional(MCP)
http://vamsikomarneni.blogspot.com/
http://www.linkedin.com/in/vamsikomarneni
![]() |
0 |
![]() |
thea3100:
Thank you, now I'm getting The following error:
"the namespace '<global namespace>' already contains a definition for '?'
I have no idea what could cause that, since I've never seen that error and I don't get it when I try what I think that you're trying to do. Post the code causing the error with an explanation of what you are attempting or what you expect to happen.
NC...
![]() |
0 |
![]() |
thea3100:
Thank you, now I'm getting The following error:
"the namespace '<global namespace>' already contains a definition for '?'
HI thea3100
This issue is not caused by NC’s code.
There is the solution from http://bytes.com/forum/thread574554.html
Dave Sexton:
Use the Find and Replace tool to search for all classes with the same name
as yours and either rename them or just rename yours :)
If I’ve misunderstood your problem, please feel free to let me know.
Thanks.
Lance Zhang
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
I am no longer getting the error when using NC01's server side code. But it is still not keeping the tab selection. Should I be still using the javascript code for the hidden field? here's what my server side code looks like so far:
protected string YourTabSelection
{
get{
object sessionObject = this.Session["YourTabSelection"];if (sessionObject == null){
sessionObject = "1";}
return (string)sessionObject;}
set{
this.Session["YourTabSelection"] = value;}
}
if (!Page.IsPostBack)YourTabSelection = hdnNewPanel.Value;
else{
hdnNewPanel.Value = YourTabSelection;
}
thanks for all your help...I'm getting close, there's just something I'm missing..that's where you experts come in, I'm a very novice user! thanks again!
![]() |
0 |
![]() |
> Should I be still using the javascript code for the hidden field
Of course. That is what actually sets the menu visibility isn't it?
NC...
![]() |
0 |
![]() |