Sunday, March 11, 2012

Dropdown list gets updated too often

Hi Pattiman,

Can you paste your code here so that we can check your problem! Thanks in advance!

Regards,


Hi!

A change in any of the radiobutton controls updates the content of the drop down list? If not, can you try putting the drop down list in an independent, individual, updatepanel, and see if it helps?

Juan


Hi.

I tried added the dropdownlist in a separate UpdatePanel, but the problem stays the same.

I've added my HTML. Hope that this helps.Confused


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="formsteps odd">
<table class="formsteps" style="margin-bottom: 0px">
<tr>
<th>
<span class="asterix">*</span> Uzelf verzekeren</th>
<td>
<div id="dvUzelfTonen">
<asp:RadioButtonList ID="rlUzelf" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rlUzelf_SelectedIndexChanged" AutoPostBack="true" onclick="UzelfTonen();" onchange="AanvullendeGegevensTonen(true)">
<asp:ListItem Value="true">Ja</asp:ListItem>
<asp:ListItem Value="false">Nee</asp:ListItem>
</asp:RadioButtonList></div>
</td>
</tr>
<tr id="Partner">
<th>
<span class="asterix">*</span> Uw partner verzekeren</th>
<td valign="middle">
<div id="dvPartnerTonen">
<asp:RadioButtonList ID="rlPartner" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rlPartner_SelectedIndexChanged" AutoPostBack="true" onclick="PartnerTonen();">
<asp:ListItem Value="true">Ja</asp:ListItem>
<asp:ListItem Value="false">Nee</asp:ListItem>
</asp:RadioButtonList></div>
</td>
</tr>
<tr id="trAantalKinderen" runat="server">
<th>
<span class="asterix">*</span> Aantal kinderen (thuiswonend tot 18 jaar)</th>
<td>
<asp:DropDownList ID="ddlAantalKinderen" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlAantalKinderen_SelectedIndexChanged"></asp:DropDownList>
</td>
</tr>
</table>
<asp:Panel runat="server" ID="pnVerzekerdeKinderen" />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rlUzelf" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="rlPartner" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlAantalKinderen" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel

Hi!

If you say that putting the drop down list inside a separate update panel doesn't help, so I assume that a change in he radiobuttons triggers a re-population of the drop-down list. If so, how many items does it get? The query you use to bind the data, takes too long?

Can you post you code-behind code, so we are able to actually run your code?

Cheers,

Juan


Hi Pattiman,

First a little suggestion. When your controls are in the update panel and they need to trigger each other then you don't need to specify triggers. Triggers are used for controls that are outside the updatepanel and need to trigger controls inside the updatepanel to get updated. But i have a question about the situation you are trying to create.

Why are all those controls in the updatepanel?

When do you want the dropdownlist to be updated?

Regards,


Hi Juan.

posting the complete codebehind is not an option. I'm working on a insurancecompany site. So I think that you understand the problemWink

The radiobuttons and dropdownlist don't trigger each other. There are some other controls on the page that need to change.


Regards

Patrick


Hi Dennis.

The controls don't need to influence each other. Other controls (outside the update panel) need to be updated whenever one of the radiobuttons or dropdownlist changes.

The dropdownlist contains 10 strings. No connnection with a database.

Regards

Patrick


I would also think you'd understand everyone else's problem - the issue you are having is being explained cryptically. Your html looks fine its the code-behind that is the issue...accokmplish?

If you Datalist is not being triggered by the selections in the update panel then you need to make sure you are coding to best practices of .Net anyways - and that practice is bind once if that data is not going to change...(not speaking selected choices just the actual data bound to the DDL). It seems to me from the explanation that you are databinding each time there is a postback (asynch or not)

Try setting the data binding for your DDL (dropdownlist) in its own method call. On Page_Load or OnLoad event do a

if(!Page.Postback)

{ BindDataList()}

This will prevent the datalist from rebinding if it just the ten selections or what not (not bound to a datasource) - bind once it is all you need...when the page loads the first time...

create a methodcalled

void BindDatalist()

{

insert whatever you need to databind the data..

}

If your radio button etc need to modify it - and rebind - then from the selectedindex change event or whatever event - call the BindDataList() from the event....

But seriously - without a mock sample of the code behind that replicates your issue its like three blind men trying to find the other's fallen eye contact... just ain't gonna happen...

The other poster is correct get rid of your postback triggers.. they are only used for external buttons outside of the update panel that need to change the update panel...if there is something inside another update panel on the page that needs to change - explicitly call a UpdatePanel(replace with name of it the id).Update() from code behind on your selected index change event to invoke the update of the other panel... or use nested UpdatePanels...

Naturally without knowing what the code-behind is this is an un-educated guess but would explain your flickerering and constant rebinding...


Hi Jody.

I will try to make it more clear to you and the other contributors.

The page I'm making gives the user the opportunity to insure two adults and several children. So the radiobuttons are used for the parents and the dropdownlist for the children. If the radiobuttons are 'enabled' additional textboxes become visible, so that the user can enter details, like birthdate and surname. De dropdownlist is used to indicate the number of children. If a number is choosen from the list, several textboxes for those children becom visible.

The contents of the dropdownlist is added in the Page_Load section:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlAantalKinderen.Items.Add(new ListItem("- Geen -", "0"));
for (int i = 1; i <= DLR_MAX_AANTAL_KINDEREN; i++)
{
ddlAantalKinderen.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
}

I've placed a breakpoint in that function, but it's not reached while changing one of the radiobuttons.

I will create a testapplication that shows this problem, so that I can post the complete code here.

The asyncpostbacktriggers have been removed...

Regards

Patrick


Hi Patrick,

The controls that needs to be update must be inside the updatepanel. The three other controls need to be defined as triggers:

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"></asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label><asp:LabelID="Label2"runat="server"Text="Label"></asp:Label><asp:LabelID="Label3"runat="server"Text="Label"></asp:Label></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="rlUzelf"EventName="SelectedIndexChanged"/><asp:AsyncPostBackTriggerControlID="rlPartner"EventName="SelectedIndexChanged"/><asp:AsyncPostBackTriggerControlID="ddlAantalKinderen"EventName="SelectedIndexChanged"/></Triggers>

</

asp:UpdatePanel></div></form>

</

body>

</

html>

Is this situation the labels are updated when the selected index is changed. Hope this helps

Regards,


Thanks I think I know now where you are coming from...here is what you can do:

Seems like a simple issue and I would go about this by developing the form first in a non-ajax enviroment to take it out of the equation.

Once you have it working as you desire then you can probably put it all into a single update panel. If all there is is the ability to choose from the drop down and display a number of childred textboxes (assuming for name etc) then you should be able to write this as you would a non-ajax app - get it working and then - put the update panels around it...

One of the fallacies with Ajax is the 'magic' that appears to go with... In your scenario your probably do not need multiple update panels as this is just a portion of a form and you are already grouping the business requirements together. Also keep in mind that a asynchronous postback still posts the page back to the server just that the server then only sends back what needs to be updated... so try to keep it simple - very rarely do there need to be postback triggers less you have a very complex form and even then I would argue there would be a simpler way to accomplish the task - hopefully that helps a bit...

You mention that you are not hitting a breakpoint on the DLL binding - but superceded that with when the a radio button is selected... please do provide a sample... that replicates and remember if you can make it work in as a non ajax with the postbacks etc then odds are you simply add update pnales when it it is working the way you prefer...


Hi PattiMan,

Looking at your code, I would try to use UpdatePanel only for the parts that actually are being updated. If you put your radiobuttons inside the same panel as the dropdown, even if they are not influencing it, it will get refreshed anyway. You were talking about a flickering and that only happens when the control is being refreshed.

I would put the dropdownlist inside its own UpdatePanel, thus making it refreshing ONLY by its own events (no triggers yet), and then, as you identify exactly which events from the other controls causes a DDL databinding, you set them as triggers. That should do the trick.

Regards,

Juan

No comments:

Post a Comment