I have three web controls that has to update a gridview inside an updatepanel.
The markup is like this:
<asp:DropDown></asp:DropDown>
<asp:Button></asp:Button>
<asp:DropDown></asp:DropDown>
<asp:UpdatePanel>
<asp:Gridview></asp:Gridview>
</asp:UpdatePanel>
I cannot put the updatepanel before the first dropdown because I have used the bootstrap datepicker and that does not behave properly if I put the updatepanel in the start.
Related
I have a web page with an update panel in it.
Inside the update panel I have a panel with a user control like this:
<asp:UpdatePanel ID="updatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlFiles" runat="server" EnableViewState="true">
<files:FilesControl runat="server" ID="filesControl" />
</asp:Panel>
</ContentTemplate>
I have a list of checkboxes that whenever the user checks one of them I want to add another FilesControl to that panel
so I am doing it like this:
FilesControl files = (FilesControl)LoadControl("~/UserControls/FilesControl.ascx");
files.ID = XXX;
pnlFiles.Controls.Add(files);
But on every postback (every checkbox checked) the panel loses the last state and the controls added are wiped out, so the panel actually returns to its initial state every time and I can't ad more and more controls to it.
I enabled view state and it didn't help.
What am I missing out here ?
As requested, my comments as answer:
You need to add the control(s) to the page on every postback in Page_Init or Page_Load(at the latest) with the same ID as before.
The ID is unique, I generate it. I add the controls on the checkbox
checked change event chkCompare_CheckedChanged
While it is perfectly fine to add a control dynamically in an event, it is necessary to re-create this control on the subsequent postbacks. That must be done in Page_Load at the latest (better: Page_Init). So you need to store somewhere which controls you have already added to be able to re-create them. Maybe it is sufficient to store the control-count in the ViewState.
So I should store the controls I added in the ViewState object and
then re-add them to the panel on Page_Load ?
No, you shouldn't store the controls in the ViewState but the information that is necessary to re-create them. How do you know what you need to add? Of course you could also use a webdatabound control like Repeater, DataList or GridView where you only need to assign a DataSource and the persisting stuff is done automatically for you.
That is what is done with all controls even if you add them declaratively(on aspx). But those controls are re-created automatically by ASP.NET. All variables are disposed at the end of the page's life-cycle since the communication between the client and the server is stateless and disconnected.
I have an asp.net application in which i have nested master pages. The problem is that i have many difficulties to use an update panel to refresh only a part of the page in a child master page or a web form which inherits from a master page different of the parent one. I think this problem is caused by my use of update panel in the parent master page . So , because I worked with the user controls in WPF application and i'm using to put a container which its contents( which is a user control) changes dynamically when i need to, i wonder if i have two user controls ( login and inscription for example ) and i have this code in my view :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
//putting a user control
</ContentTemplate>
</asp:UpdatePanel>
How can i change dynamically the user control used in the update panel?
Is it a good approach to do like this?
Thanks,
The documentation on MSDN states:
To add items to the UpdatePanel control dynamically, use the
ContentTemplateContainer property, which enables you to add child
controls without having to create a custom template that implements
the ITemplate interface.
I found that anytime I try to use the UpdatePanel, it ends up causing tons of problems. I've found using AJAX (with jQuery to make it easier) to be a much better solution.
I'm having an update panel which is refreshing the gridview every 2 seconds. I've added modalpopup extender to confirm user action within the gridview. And I've wrapped all other controls in my asp page in another update panel to avoid the page being refreshed everytime.
While I think I'm only refreshing the gridview the whole page is refreshing and the modal popup extender disappear after 2 sec. Please help me with a solution.
strong text
This is how my aspx page looks like.
--Mainupdatepanel--
--div--
--table--
--dropdown--
--button--
--textbox--
--/table--
--updatePanel1
--gridview with item template buttons--
--/updatepanel1--
--updatepanel2--
--confirmbuttonextender--
--confirmbuttonextender>
--modalpopup--
--/modalpopup--
--panel--
--buttons -- for modalpopup
--/panel--
--/updatepanel2--
--/div--
--/MainUpdatepanel--
In the code behind:
Timer_click event I've called updatepanel1.update();
In the click events of the button inside gridview I've called updatepanel2.update();
If you have multiple update panels on the page and you want them to refresh independently you need to make sure you set the UpdateMode property of the update panels to Conditional
Also as it seems both update panels are in turn wrapped in a update panel you will need to alter the ChildrenAsTriggers property to be false else the mainupdatepanel will update with the inner update panels
I have found many equivalent questions here, but non seem to apply to my problem.
I am dynamically loading controls into a Nested Masterpage. The button click event is not firing for buttons in different usercontrols, loaded in the Nested Masterpage.
When debugging, it seems like just a normal postback that occurs when a any button is clicked on the nested masterpage. No events are fired / caught in debug. The nested masterpage re-loads (post back), and that is about it.
Some Info that might pertain to the situation:
I am using codebehind for my methods, and where I expect to catch the event.
I have put the code that loads the uc's in the Nested MasterPage's init sub.
I have tested, and adding the control to the panel manually, everything is wired up as expected, throughout the lifecycle, and events are fired for the manually added control.
I have tested with using a static client ID for my buttons, as I thought the event might be wired up incorrectly. This did not have any effect.
I have manually assigned unique id's to my controls, no effect.
All usercontrol have and keep the correct properties set for them (Description, Quantity etc.).
I am reloading the usercontrols every time the nested masterpage loads.
I am not exiting on ifIsPostback, but instead reloading controls on every postback, as one of the buttons on the controls, might remove that control, and the new remaining controls need to be rebuilt on Page Init of the masterpage.
There is a script manager on the Master Page (not the nested masterpage).
I am making use of Ajax in the content pages, but not in the Nester Masterpage.
There is no update panel on the masterpage or nested masterpage.
All events are firing in a normal fashion on the content pages.
From my content pages, I remove and add controls to the nested masterpage dynamically. This works well and controls are loaded accordingly.
I am not setting the controls from the content page to the masterpage directly.
I am creating controls in my content pages, and pass them to a routine that manages a custom object containing all my controls, add and removing controls form this object as necessary.
In my Nested Masterpage Init event, I step through my custom controls
object and add them to a panel.
I am not sure how to debug the postback event in the browser, as I am
not making use of an udpate panel and Ajax for these controls in the
Nested Masterpage.
Here is the generated HTML for the Control that works (Manually dropped in at design time)
<input type="image" src="bookings_media/buttons/add-another-unit.jpg"
id="ContentPlaceHolder1_ucAddAnotherUnit1_butAddAnotherUnit"
name="ctl00$ctl00$ContentPlaceHolder1$ucAddAnotherUnit1$butAddAnotherUnit">
This is the rendered HTML for the dynamically added control:
<input type="image" src="bookings_media/buttons/add-another-unit.jpg"
id="ContentPlaceHolder1_ctl02_butAddAnotherUnit"
name="ctl00$ctl00$ContentPlaceHolder1$ctl02$butAddAnotherUnit">
Any ideas what might be snagging here:
Try using OnCommand instead of OnClick regarding the ImageButton.
What I did is, I have made 2 user controls. One control is inside the other.
NoW one control has a buttton and a data grid and datalist in it. When pressing button I am filling datagrid while datalist visiblity false. This is working fine. But now when I press some link button in datalist data, it should call item_command event but it is not calling.
I have also used a Updatepanel as a wrapper(all controls are inside it).
Please suggest what may be the reason for that.
Thanks
Set the enablePartialRendering to False of the ScriptManager like this
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false">