Loading user control dynamically loses data - vb.net

I have a created a user control. This user control I dynamically load on a page inside Telerik Panelbar control. I have done all necessary coding to save the viewstate and load this dynamically created usercontrol every time page loads.
On this User control I have a asp panel. By default this panel is invisible. When user clicks a button on this user control panel is made visible. On page load of this user control I populate all the controls on this panel.
Everything works fine if I don’t load this use control dynamically but when I load this user control dynamically and if I make panel visible by default then only all fields on the panel are populated. But if I make by default invisible and on button click make panel visible none of the text boxes or comboboxes are populated.
I populate comboboxes on page load of the userControl but inbetween postbacks all the comboboxes on the user control loose data.
ON the parent page I am saving the viewstate
This is my code on parent page to dynamically load userControl ( which has panel on it)
Dim ucPiggyBank As SubscriberSetupPages_UserControls_PiggyBank = CType(LoadControl("~/SubscriberSetupPages/UserControls/PiggyBank.ascx"), SubscriberSetupPages_UserControls_PiggyBank)
With ucPiggyBank
.PiggyBankID = account.Id
.ID = account.Id.ToString
'Setting up following 3 properties here to avoid database trips
.PiggyBankEligibleAccounts = piggyBankEligibleAccountCollection
.MemorizedNames = memorizednames
.Period = period
End With
radPanelNewChild.Controls.Add(ucPiggyBank)
radPanelNew.Items.Add(radPanelNewChild)
radPanelNew.Expanded = True
‘this is the Panel item on parent page of Telerik Panelbar control.
Dim radPanelPiggyBank As RadPanelItem = DirectCast(pnlbarPiggyBank.FindItemByValue("TestItem"), RadPanelItem)
With radPanelPiggyBank
.Items.Add(radPanelNew)
.DataBind()
End With
‘I am doing everything for saving viewstate on parent control
This is the code on page load of userControl
If Not IsPostBack Then
If m_PiggyBankID <> Guid.Empty Then
'Load data
Call GetPiggyBankDetails()
End If
I have a edit button on the user control which makes panel visible. It makes panel visible but with no data.
Can you please tell me what’s happening?
Thanks in advance.

If data is posted, you can get it from Request.Form[control.UniqueID] , but don't use viewstate possibilities hehe if control added dynamically.

Related

How to show a User Control after loading all its controls?

I have a panel in a WinForm application, is used to display a User Control. The code is this:
Public Sub AddUserControlsToPanel(us As UserControl)
pn.Dock = DockStyle.Fill
pnContainer.Controls.Clear()
pnContainer.Controls.Add(pn)
End Sub
This code works perfectly but while the User control is dispalying on the panel, I can see that it renders too slow. I have also some User Controls with a DataGridView or a ListView that display data from the data base, on those cases, the User control takes between 5 to 10 sec to render completly.
Here is what happends when I load a User Control with Textboxes, Buttons and Lables and in this case (ListView, the same happends on a DataGridView) takes time to load and it's not in it position when displayng.
What can I do to display it faster? or How can I display it after loading all its control?

VB.NET Module-level variable to store count of child forms

In this exercise, you’ll create an application with a multiple-document interface that consists of a parent form and two child forms.
Open the project and add a parent form
1. Open the CalculateFlooringCosts project in the CalculateFlooringCostsMDI directory. Then, review the code for the Carpeting Costs and Hardwood Costs forms so you understand how they work.
Add a form to the project, and set the IsMdiContainer property of this form to True to identify it as the parent form. Resize the form so it’s large enough to hold several child forms, and use the Application page of the Project Designer to change the startup form to the new form.
Add the File menu to the parent form
Add a MenuStrip control to the parent form. Then, use the Menu Designer to add a File menu to the parent form. This menu should include four menu items that display a Carpeting Costs form, display a Hardwood Costs form, close the active child form, and exit from the application. Give each menu item an appropriate name, include access keys for the menu and menu items, and include a separator bar between the Close and Exit items.
Add an event handler for the Click event of each item in the File menu. The event handlers for the New Carpeting Costs and New Hardwood Costs items should create a new instance of the appropriate form, set the parent form to the current form, and display the form. The event handler for the Close item should close the active child form, if there is one. And the event handler for the Exit item should exit from the application.
Change the Exit buttons on the Carpeting Costs and Hardwood Costs forms to Close buttons, and change the StartPosition property of these forms to WindowsDefaultLocation.
Test the application to be sure that the items in the File menu work as expected.
Add the Window menu to the parent form
Add a Window menu to the right of the File menu. Then, add three items to this menu that will let the user arrange the forms in a cascaded, vertical, or horizontal layout.
Give each item in the Window menu an appropriate name, and then add an event handler for the Click event of each item that arranges the child forms appropriately.
Set the MdiWindowListItem property of the menu strip so the Window menu will display a list of the open child forms.
Test the application to be sure that the items in the Window menu work as expected.
Add a toolbar to the parent form
Add a ToolStrip control to the parent form. Then, add two buttons to this toolbar with the text “Carpeting Costs” and “Hardwood Costs” on them. Be sure to assign appropriate names to these buttons.
Add an event handler for the Click event of each button that uses the Click event handler for the associated menu to display the form.
Test the application to be sure that the toolbar buttons work.
Add a status bar to the parent form
Add a StatusStrip control to the parent form. Then, add a single ToolStripStatusLabel control to the status bar.
Add a module-level variable to the parent form to store the count of child forms, and give this variable an initial value of 0. Add code to increase or decrease the value of this variable each time a new form is opened or closed.
Add a procedure named DisplayFormCount that sets the Text property of the ToolStripStatusLabel control to “Number of child forms currently displayed: ” appended with the current form count. Then, add code to call this procedure when the form is loaded and each time the form count changes.
Test the application to be sure that the form count is displayed properly.
It's steps 15 and 16 I am stuck on.
I have tried this:
Private Sub DisplayFormCount(Sender As Object, e As EventArgs) Handles Me.MdiChildActivate
Dim activeForm As Form = Me.ActiveMdiChild
Me.sbMain.Items(0).Text = "Number of child forms currently displayed: " & Convert.ToString(Me.MdiChildren.Count)
End Sub
And it works for the most part. Upon form loading, it shows 0, then adding a form will make the count increase by 1. The problem is when I go to close the first child window, it doesn't subract. Afterwards all window closes reduces the count by 1 and when all windows are closed, it still says there's a count of 1.

VB.NET - Navigating without loading another form

I'm currently developing a simple enrollment system for our school project. I have multiple modules that when clicked will open a new form with another set of sub modules.
However, I hate how forms load every time I open a new form. Is there like a way that when I clicked say for example "Enrollment" button, instead of loading a new form, it will change all the controls instead. Tried using User Control but it keeps crashing my program down after I created 2 user controls and load them in one form.
Main Form;
Enrollment Sub Form
Please help me guys.
As LarsTech mentioned I would use user controls instead of forms.
Each user control would be setup the same way as your form is, but can be loaded to a panel on the main form, allowing for a single form to show all content.
Dim myControl = New ControlYouCreated
panel1.Controls.Add(myControl)
myControl.bringtofront
This for example, will bring in the contents of the user control you created, into your form1 panel.

How to capture popup webpage in tabcontrol browser

How to capture the popup when clicked when the button is clicked in webbrowser it opens a popup webpage i need to capture the popup webpage to the tabcontrolbrowser
I think I understand what you are trying ask for. I have had a similar issue where I must display a form nested within another form. To do so I have used code similar to this:
aForm = New TLoginForm
aForm.TopLevel = False
pnlLoginPanel.Controls.Add(aForm)
If aForm.WindowState <> FormWindowState.Maximized Then
aForm.WindowState = FormWindowState.Maximized
End If
aForm.Show()
I like using a panel control to contain the form I am instantiating. It is just easier for me to understand the bounds of the form when it is getting displayed and it is easier to use a panel control's Controls.Add ability than a tab-page's alone. When I am using a log-in form or another type of form nested within another form I create a panel control to 'hold' the form inside and provide bounds for it to be displayed in. Then the TopLevel property of the log-in form must be set to False so that the form I am displaying knows it will not be displayed on its own as a top level window. Be sure to do this as an error can be encountered otherwise. The WindowState.Maximized is to ensure that the form fills the panel.

Loading new form within a navigation tab in ms Access 2010

I have created the following navigation structure in a Microsoft access 2010 database:
You can see that there are two tabs, and the data for the tabs is populated with information linked to the ClientID, which is stored in an un-editable textbox at the top of the form. When the Communications Forms tab is selected, a list of communications forms that have been completed for the specific ClientID is shown. And there is a button to create a new form. My question is how do I write the macro so that clicking on the Create New Form button will cause a blank new form to be loaded in the space that is currently occupied by the List of Forms?
Below is what I have so far. It sends the user to a new form instead of embedding the new form underneath the Communication Forms tab in the current form. How can I change the below so that the blank new form is loaded under the Communication Forms tab in the current form, so that all the navigation controls remain visible/usable?
EDIT:
To address HK1's assumptions below, I am adding the following description of the steps I took to create the form in the screenshot above:
1.) I created a blank form in design view.
2.) I added a listbox to list client fullname and id, and a textbox to filter the listbox.
3.) I added the clientid and fullname textboxes to the form, and set them to change based on
what the user selects from the listbox
4.) I dragged a navigation control onto the form next to the listbox
5.) I dragged a form called "ListOfForms" onto a new tab in the navigation control to create the tab
6.) I added the CreateNewForm command button to the ListOfForms form while embedded in the main form
Here is the result of HK1's suggested code:
While I appreciate it, it does not do what I need. You can see that it just adds an additional row to the list in ListOfForms. Instead, I need the code to place a blank MyForm in the place of MainForm where ListOfForms is currently located. Thus, under the CommunicationsForms tab, all the user would see would be a blank MyForm object, which is a different form than ListOfForms.
When I click on the place where ListOfForms is located in Layout View, I see that it is called NavigationSubForm in the Property Sheet. Thus, NavigationSubForm would swap in MyForm in place of ListOfForms when the user clicks on the Create New Form command button. But if the user clicks on CommunicationForms tab again, ListOfForms would again be placed in NavigationSubForm.
I tried the following:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm!NavigationSubform = MyForm
End Sub
But it generates a Runtime Error '438': Object doesn't support this property or method.
Next, I tried:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm.NavigationSubform.SourceObject = MyForm
End Sub
This causes the NavigationSubForm to go blank, so that ListOfForms disappears. This seems like I am on the correct track, but what do I need to do to get it to put a blank MyForm in the NavigationSubForm instead of just an empty space?
The form you have labeled as "List of Forms" appears to be what's called a continuous form, and I'm guessing it's inside a subform control located on a another form. I'm also guessing that your Create New Form button is probably located on the header section of your continuous form. I'm also making the assumption that your continuous form/subform is bound to an editable recordset/recordsource but there's no way I can tell this by looking at the screenshot.
With these assumptions in place, the code for your Create New Form button would probably be something like this:
Private Sub cmdCreateNewForm_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord, , acNewRec
End Sub
If any of my assumptions above are incorrect than it's likely this code won't work as expected.
Be aware that New Records in continuous forms (and datasheet forms) always appear at the bottom of the list. I'm not aware of any easy way of making them appear anywhere else.