Usercontrol not retaining value - asp.net

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

Related

How to get the current page of Vmware clarity wizard?

We are using VMware clarity wizard to render wizard pages dynamically and we need to have custom logic to access the current page id/step id of the wizard for validation and other functionalities.
When trying to access page of the wizard, using pagesCollectionService and navService, we are getting the id's correctly for the first time e.g clr-wizard-page-0, clr-wizard-page-1 etc.
But the Problem is on click of cancel/submit from the wizard, the wizard id's are not getting reset, that is when we again open the same wizard the wizard page id's are in continuation to the previous id's
e.g :clr-wizard-page-4, clr-wizard-page-5 etc.
Is there a way by which we can access the page of the wizard by using any other property.
Note: Wizard pages are dynamically rendered using json
Attaching image : page id's that come up when we open the wizard for second time
enter image description here
Adding more information,
Please find the stackblitz link for more details:
https://clarity-light-theme-v013-phyhyk.stackblitz.io
Here we are rendering wizard pages, driven by config
For every wizard page we are displaying angular dynamic forms, where config contains all the information for the form fields .
Since is being called inside a for loop, we need to have a function where on click of next/back or on click of step of the wizard we should be able to validate the current form fields and store the current form fields value.
I have added (clrWizardCurrentPageChanged)="resetFormValidity()" and on every page change i am trying to retrieve the page id using wizard.currentPage.id, but the id's are not getting reset and when i access the multiple times, i am getting incremental id's : clr-wizard-page-4, clr-wizard-page-5 etc.
We are using the below versions :
"#clr/angular": "0.11.30",
"#clr/icons": "0.11.30",
"#clr/ui": "0.11.30",
Is there any other way where i can determine which page it is currently, so that i can compare that with config and continue with validation and form submission.
The Wizard has a property called currentPage which will tell you the current page. The public methods of the Wizard are at https://v2.clarity.design/wizards under the Wizard Deep Dive section, which might replace the need to inject and use the internal services which aren't meant to be used directly in applications (from what I understood in your message, an isolated demo would help greatly).
#ViewChild() wizard: ClrWizard;
get currentPage() {
return this.wizard.currentPage;
}

Read hidden field values from another page

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

FindControl won't find my dynamically added UserControl

I'm working on a project where the page load certain controls depending on the index available. The loading occurs in the page load where the method PopulateSearchField is called.
Within this method, all the UserControl are added on the page using : Page.LoadControl("path");
The page load and all the required controls are on the page. My problem is when the user click on the Search button the event is triggered and a query is built based on the user input int those controls. Unfortunately, the method isn't able to produce a proper query as it is unable to find any of the controls on the page.
With a temporary ControlCollection variable, I've been able to see that the number of controls on my page is 3 when it should be something from 4 to 10. Those 3 controls in the collection are the static label and buttons on the page.
I don't know if something is wrong with the code or if it's a page cycle problem as this solution used to work on framework 1.1. Yeah, I know this isn't the best thing to do so, but they did it this way and I gotta make it work.
I'm not sure if it is the migration that has caused the problem or not.
Thanks a lot, David!
When you click the button, the controls are no longer available server side when your click handler is being processed. The page, server side, has no knowledge of the controls you created dynamically since there are no server side controls for the posted values to map to. If you want to find the values, you need to inspect the posted control data and not rely on the server side asp.net control heirarchy.
You could also write all the data you require to a hidden field via javascript and then read the hidden data server side since it will will be posted.
The following is occuring:
Creating controls dynamically
Posting controls data on click
ASP.NET maps the data to the existing controls it knows about.
Your controls are not found so the data is no mapped to anything.
You need to add your controls before the mapping occurs (in PreInit). Check out the Page Lifecycle and you will see how it ties all the controls and data together.
Are you re-adding the controls to the new page when the user clicks search?
Remember... every time the user hits your server for that page... a new Page object is created. If you're dynamically adding controls, you have to do it every time the page loads.
Additionally, since you seem to want to get values out of the controls, you're going to have to make sure that the controls are created with the exact same ID property every time, and created before viewstate is loaded, if you want them to retain their values.

Change language/culture in Ajax enabled ASP.NET web application

I've implemented an ASP.NET web application that supports 5 different languages.
The web application has 5 .resx files that contain the resources required in order to display the website in the languages it supports. To display the site in the language that the user has selected, I've been setting the Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentUICulture in the InitializeCulture page event.
Some of the pages have UpdatePanels wrapped around the content.
From what I remember (from 3 years ago when I was researching globalization), in order to change cultures you have to do a full page update.
So here's the problem:
The user opens a tab and starts working on some page that has an UpdatePanel surrounding the content.
Then the user opens another tab and selects a new language.
The user returns to the original tab and causes a postback to the server...at this point the page never returns control to the user.
How do I get around this problem?
Thanks,
-Frinny
To get around this problem I ended up storing the user's cultural settings into a HiddenField for each page (did this in the MasterPage really). This way I can access the user's original culture/language settings in the Page InitializeCulture event. The user would have to click enter on the URL or exit the page to use the "default" language/culture selected in the other tab.

ASP.Net Page abstraction

We have a win application that shows a web form in a web browser.
In order to get data from this web form we are using a hidden text box and get its text using HtmlDocument object of web browser control.
I want to make an abstraction of this web form that has this text box element so that other forms can use this abstraction.
I made a web control and put the text box on it.I thought that if I put this control on my page it would have the text box.When i ran my application I noticed that the text box had been rendered but had its control name in its name (WebControl$TextBoxName) and its id(WebControl_TextBoxName) and the win app throw an exception since it couldn't find the element by its id(TextBoxName).
So here's my question:
How can I make an abstract web form/web control that has some elements on it and I can use it to make my final forms have these elements on them? (their names and ids should not be changed)
Thank you for your help
dotNet 4.0 supports static id's so they don't get mangled, read up on Client Id Mode
Alternatively, you could override the render of your control to output a standard html hidden form field with whatever ID you want, and then also add a custom property that will return the textbox that will hide the fact that it isn't an asp.net server control.
Though I've never used the browser control in WinForms, I think what you want to use is a Master Page. Assuming what you're rendering in the browser control is an ASPX page, create a Master Page with the hidden text box that you want to grab your data from, and tell all of the pages you want to have that common control on to use your Master Page. When the page renders, the control id will then be "ctl00_TextBoxName". There is no way of getting around the ID concatenation, since unique IDs are needed and that's the only way to guarantee uniqueness with all the nested control abilities of ASP.NET. However, doing this will guarantee you always have that control named the same on every new form you create that inherits the Master Page. Hope that helps!
In summary (because who reads paragraphs?):
Create Master Page
Place your common control in the Master Page
Have your Form inherit the Master Page
You can read up on how Master Pages work in MSDN's Documentation.

Resources