vb.net clearing panel contents inside update panel before postback - asp.net

I have a basic update panel which contains a panel inside. This inner panel dynamically creates controls based on a dropdown value.
The problem I am having is when I change the dropdown item and it updates the updatepanel, I want to clear the contents of the inner panel before calling the function that populates the controls.
Panel code:
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="Dropdownlist1" eventname="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="custompanel" runat="server">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
I have a function populatecustompane() that populates the panel.
I can get the new controls to show the 1st time i change the dropdown, but the old controls dont get removed

Call custompanel.Controls.Clear before adding the new controls.

Related

Dropdown event stops firing after specific selection

I have 2 asp dropdown controls and an asp grid control in an Updatepanel. Update Panel is set properties as UpdateMode="Conditional" ChildrenAsTriggers="true".
On change event of both dropdown I am calling a method which fetches data from SQL Table and binds to grid control. This works fine till data is less. Whenever I select a value from dropdown for which data is around 900+ records, it binds data to grid without any error. But doesn't trigger any other dropdown change event.
<asp:UpdatePanel ID="uPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:DropDownList ID="ddldept" runat="server" OnSelectedIndexChanged="ddldept_SelectedIndexChanged"
AutoPostBack="True"/>
<asp:DropDownList ID="ddlYr" runat="server"OnSelectedIndexChanged="ddlYr_SelectedIndexChanged"
AutoPostBack="True"/>
<asp:DataList ID="gvData" runat="server" OnItemDataBound="gvData_ItemDataBound">
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddldept" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
What could be the reason of event stops triggering?
EDIT 1:
Found error in console:
POST http://devserver:1111/mysite/SitePages/Main.aspx 500 (Internal Server Error)
ScriptResource.axd?d=FcwEEmnie6xhah_BvAg_MQP-cTp24dyFdRx9c2UxylFp5s8-W18rfLHBOC-uoS-F5J3jgyRFMZWkZS…:4803
Found the answer.
Just had to add following entry to web.config.
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="3001" />
</appSettings>
Started working

ASP Update Panel

I implemented an update panel with a treeview control inside. The treeview control will cause a postback via Javascript which leads to the OnNodeChecked being triggered.
I have wrapped this in an UpdatePanel control, but I still get the blinking effect on my page. I also have a scriptManager implemented in the page. Does anyone know what I can do to avoid the flicker?
<asp:UpdatePanel ID="updateTreeViewPanel" runat="server"
ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:TreeView ID="tv_WLG" runat="server"
OnTreeNodeCheckChanged="tv_WLG_TreeNodeCheckChanged"
OnSelectedNodeChanged="tv_WLG_SelectedNodeChanged"
onclick="javascript:postBackByObject(event)"
ShowCheckBoxes="All">
</asp:TreeView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
I would recomend adding a trigger...
<asp:UpdatePanel>
<ContentTemplate>
...your existing code
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tv_WLG" />
</Triggers>
</asp:UpdatePanel>
The clientside script you're targeting may occur outside the scope of the update panel however. You might try handleing your click event in the codebehind instead.
What you can do is add an onload event to the updatepanel and trigger that using __doPostback() like so. Then whenever the click event fires you can handle it in the onload event of the updatepanel
<asp:UpdatePanel ID="updateTreeViewPanel" runat="server"
ChildrenAsTriggers="true" OnLoad="UpdatePanel_Load" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:TreeView ID="tv_WLG" runat="server"
OnTreeNodeCheckChanged="tv_WLG_TreeNodeCheckChanged"
OnSelectedNodeChanged="tv_WLG_SelectedNodeChanged"
onclick="__doPostback('updateTreeViewPanel', '');"
ShowCheckBoxes="All">
</asp:TreeView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
The reason your current method isn't working is because the postback object needs to be an object that is being handled by the update panel. Calling doPostback() with the update panel as the object will trigger the partial postback.

ASP.NET USERCONTROL WITH UPDATE PANEL INSIDE PAGE UPDATE PANEL

I have a master page with the Scrip manager. Have one page that use the master page and inside of this page i have an updatepanel. Inside this update panel i call a UserControl that have inside other updatepanel.
So i have,
MasterPage ->
Page with updatepanel ->
UserControl with update panel
The problem is that the linkbutton event inside the usercontrol updatepanel not fires.
Any help?
<asp:UpdatePanel ID="updPost" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="linkComment" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="linkComment" runat="server"
OnClick="linkComment_Click"
CssClass="PostComment" Text="Comment" />
</ContentTemplate>
</asp:UpdatePanel>
This is the code of usercontrol.
Thanks
It looks like showCommentBox() is not returning true.

trigger an async postback for an update panel from a repeater control

I have an ASP.NET Repeater Control inside an UpdatePanel. I need to update another control when clicking in an ImageButton (inside of the Repeater template). The thing is that I can't get that to trigger.
The panel upPanelRotator is refreshed... which I don't want...I just want to call back to server to update another panel - which I'll control from the server.
Any ideas?
<asp:UpdatePanel ID="upPanelRotator" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rptRotator" runat="server" OnItemCommand="rptRotator_ItemCommand">
<ItemTemplate>
<asp:ImageButton ID='imgBtn' runat="server" />
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="ItemCommand" />
</Triggers>
</asp:UpdatePanel>
You should be able to add an async postback trigger to the updatepanel you want to update. Set the control id of the repeater and the "ItemCommand" event as the event name... like this:
<asp:UpdatePanel ID="updatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="repeaterId" EventName="ItemCommand" />
</Triggers>
<ContentTemplate>
...
If PanelA has the trigger button, and you want to update PanelB, you would need to have the async postback trigger on the UpdatePanel surrounding PanelB. The problem is, you need to give the actual ID's of the buttons, which specifying imgButton like you have above won't work (because there could be many in the repeater, and async trigger requires one reference that it won't be able to find). To make this very simpe, wrap everything in the UpdatePanel, and that will make your life easier. Otherwise, you have to add the async postback triggers from code I believe.
I have right now similar situation, and I have do this so that I wrap control inside Repeater in another UpdatePanel, and I set AutoPostBack="true" of that control, and register
< asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="Click"/ >
my only consideration on this is how will a such number of UpdatePanels reflect upon performance. I have small project with few DB entry's but for larger amounts of Data, I would test performance before and after such intervention.

Async Triggers in ASP.Net

I have an update panel, an async trigger and a button outside the update panel. The button is wrapped with the trigger. All this is in one form. I load this form using the .load() method (jQuery). It works fine: I press the tab and the form loads into the other form. Then, when I press the button for the first time it fires the click event, but when I press it again nothing happens. Can you please help? I have tried putting the button in and out of the update panel and it's still not working. Here's my code:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Search" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName = "Click"/>
</Triggers>
<ContentTemplate>
...
If you're loading the form with jquery it may be something where you need to rebind an event, I'm not familiar with the .load method()
I assume this section of code works fine if you pull it off into a test page?

Resources