.NET newbie here.
I have a page with a number of sections to it. I want to create another page to have hyperlinks to this page, and hyperlinks to the sections within it.
I want all the sections to be visible if the user has clicked on the main page link, but only the section that the user has asked for if (s)he has clicked on the section hyperlinks.
How do i set the visible property of the non-requested controls (in asp:Panel's) from the link on the previous page, so they don't appear on the page when a different section is requested?
many tia
mcalex
You have the following options
Wrap each section controls inside an asp.net panel server control
When you click the hyperlink on the main page, pass the panel to enable via querystring or session as a parameter like on your linkbuton
Response.Redirect("~/myPage.aspx?secId=info")
Then on your redirected page set all panels Visibility=false inside pageLoad check for querstring value & set the panel's visible property to true or false
if(!Page.IsPostBack)
{
string panelToEnable= Request.QueryString["secId"];
switch(panelToEnable)
{
case("info"):
panelInfo.Visible=true;
break;
case("details");
panelDetails.Visible=true;
break;
default:
panelMaster.Visible=true;
break;
}
}
Alternatively you can place the section links inside the redirected page & further simplify things (remove querystring etc.)
You could inspect the Request.ServerVariables["HTTP_REFERER"]
However, if the user refreshes the page, this will change.
You have 2 ways to do this issue:
Use query string: pass your different parameter values on the query string. In the destination page/control, check the query string and make the section visible/invisible as your requirement
Use session data: use a specific key for storing the mode. When you click on the link button of other pages, use the call back function (in CSharp) to set the session data and redirect to the destination page. This page will check the data that stored in session state and make the section visible/invisible.
Pros & Cons:
The 1st solution can be used for pure HTML link but the parameter is shown in query string so user can change it to display the other sections.
The 2nd solution can not be used for pure HTML link but it prevents user changing the values in session state. So it is more security.
Related
There is some generated contents with the links on an ASP.NET page, which is created after the user inputs values and hits a button. The links take the user to another page.
When the user hits the Back button, the generated content is gone as the page returns to its initial state with the inputs cleared and generated content not there.
Is it possible to preserve the state of the page after its content has been generated and restore it after the Back button was clicked?
I think you can you can you temporary cookies.
and on load check whether cookie is exists or not.
Save the inputs in the session, so that the page will know how to correctly render on later requests. Even better, have the first code that runs when the data is submitted redirect to new page with a URL parameter that you use to know which links to show. This is a called a POST-REDIRECT-GET pattern.
I am developing a website using ASP.net.
In my home page I have 14 tree view controls. They were placed under Jquery tabs. So when a user click a tab it only appears one treeview. So in tree node changed event currently what I am doing is passing the values from query string to another page. this query string doesnt have any sensitive data. I have to pass what is the selected Tab Id and selected tree node Id.
Response.Redirect(String.Format("~/Display.aspx?tab=1&type={0}",treeview1.SelectedValue), true);
But you know URL is ugly. I dont want to use Friendly URL thing now.
So what I did was I put 2 hidden fields values in my home page and I set them when I click the tree node.
So then from the source page I used this code to acess this.
if(Page.PreviousPage!=null)
{
string tab= Page.PreviousPage.FindControl("hftab").UniqueID;
string Type= Page.PreviousPage.FindControl("hfType").UniqueID;
}
But Page.PreviousPage always return NULL. So how to solve this probelem without using sessions and query string. I just want to pass two non sensitive data behind the scenes.
IF this is about Cross page postback thing How to do this cross page post back in node change event? Is it ok to do a Cross page post back for to get only 2 values that I needed?
The method you are trying is only possible with "Cross page posting" mechanism. When you set PostbackUrl property of a server control like button, and set the PreviousPage property of Page directive on destination page; then only you will get Page.PreviousPage values.
Here are some reference:
1. http://www.codeproject.com/Tips/604553/Postback-and-Cross-Page-Posting-in-ASP-NET
2. http://www.aspdotnet-suresh.com/2010/05/cross-page-post-backing-in-net.html
I have a usercontrol with a dropdown, a textbox and a search button in the master page. I select a value in the dropdown, fill in text in the textbox and click on the button. On button click it redirects to another page but all the values are reset. How can I get the value selected in the dropdown and the text in the redirected page?
You need to post the values to the other page. You can for example pass the values in the url
redirectedUlr.aspx?value1=1&value2=2 etc...
Or you can store the value in the Session
Session["passedvalues"] = YourValues
Their is several way to handle this
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:
Use a query string.
Get HTTP POST information from the source page.
The following options are available only when the source and target pages are in the same ASP.NET Web application.
Use session state.
Create public properties in the source page and access the property
values in the target page.
Get control information in the target page from controls in the
source page.
For more information and examples, you can read the following article :
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx
I have one main page in my asp.net website.
In that page i have used gridview with hyperlinkfield.
on click of any of hyperlink, application will redirecting to detailed page.
on coming back to main page i want to hold scroll position instead of i am getting top of page.
i have tried maintainscrollposition script but its not working.
i also have used master page.
i have used button on detailed page and onclick i have used response.redirect.
How can i maintain my scroll position in this scenario ?
Since you are leaving the page and coming back, you cannot store in data in javascript or the ViewState. This leaves you with two options:
Save the scroll position in a session variable. You will have to use a hidden field to send a javascript variable to the server to save it.
You could also use a cookie with an appropriate expiry time to remember the scroll position. Using a cookie allows for a pure javascript solution.
Using a cookie is a simpler and better option in my opinion.
I am working on a legacy web application written in VB.NET for ASP.NET 1.1. One particular page has a form with a number of fields. In response to a drop-down box changing value, I am clearing a number of fields, resetting a number of drop-down boxes to the first option, and setting them all to "disabled" in the UI. To do this, I'm using jQuery. I add a CSS class to all of these fields, and then my jQuery selector is something like the following: $("*.my-css-class"). Here's some sample code to explain.
var fields = $("*.fields");
if (some_condition) {
fields.val("");
fields.attr("selectedIndex", 0);
fields.attr("disabled", "disabled");
}
The UI updates as expected in response to the above js code, but when I post back the page in response to a button click, the original values still persist on the server-side related to these controls. For instance, txtSomething is one of the fields with a CSS class "fields" (so it will get selected by the above jQuery selector). The user types "1234" in this text box and submits the form. Either the same page is posted back to itself retaining its values, or I return to this page and prepopulate the values on the server-side (for example, the user clicks an Edit button on a summary page), so the control txtSomething is initialized on the client with the value "1234". My jQuery code clears the value as far as the user sees it in the UI, and then the user clicks a submit button. If I interrogate the value with a jQuery selector, the value of this field is an empty string. When the page is posted back and I'm stepping through the code (or doing something with the value of this control), it is still "1234".
A very important point to make is that these values are sent back to the browser after being submitted once. So, picture a form being submitted, or any case where these values are bound or set on the server-side and outputted to the browser pre-populated (as opposed to being output to the browser with default or empty values). If I load the page as default (empty text boxes), enter some text, and then trigger the js function to clear these fields, the value I typed never makes it to the server.
why do you need to disable those fields? Disabling controls can make them not post values to the server ... at least that is what happens when an asp.net control is disabled server side.
Update 1: couldn't take having the doubt if it was only server side, so I looked it up :) http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1 ... "In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form.", so I was right, even when disabling it client side it won't post the value