Your RBL is outside of any updatepanel and has AutoPostBack="true" so thats what it does.
Did you try setting AutoPostBack to false and leaving it outside of an updatepanel?
If that doesn't work I guess you'll have to "work around" the intended actions with the second update panel.
Here is a simple example that works in the way that I described.If you run this, you will notice that Atlas picks up the AutoPostBack from the TextBox control and updates the Label control accordingly via AJAX. However, the AutoPostBack from the RadioButtonList causes a full PostBack. The two behave in completely different manners, and based on my experience, I believe the TextBox is exhibiting the correct behavior.
<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
void myTextBox_TextChanged( object sender, EventArgs e )
{
myLabel.Text = myTextBox.Text;
}void myRadioButtonList_SelectedIndexChanged( object sender, EventArgs e )
{
myLabel.Text = myRadioButtonList.SelectedValue;
}</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="scriptManager" EnablePartialRendering="true" runat="server" /
<atlas:UpdatePanel ID="myUpdatePanel" Mode="Conditional" runat="server">
<ContentTemplate>
<asp:Label ID="myLabel" Text="Initial Text" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="myTextBox" EventName="TextChanged" />
<atlas:ControlEventTrigger ControlID="myRadioButtonList" EventName="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel
<asp:TextBox ID="myTextBox" AutoPostBack="true" OnTextChanged="myTextBox_TextChanged" runat="server" /
<asp:RadioButtonList ID="myRadioButtonList" AutoPostBack="true"
OnSelectedIndexChanged="myRadioButtonList_SelectedIndexChanged" runat="server">
<asp:ListItem Value="Radio Button 1" />
<asp:ListItem Value="Radio Button 2" />
<asp:ListItem Value="Radio Button 3" />
</asp:RadioButtonList>
</form>
</body>
</html>
Hi,
there's an issue with list controls like RadioButtonList or CheckBoxList used as trigger for an UpdatePanel. The full postback happens because the trigger registers the list container as an asynchronous control but the postback is fired by a child control with a different id. I've added this issue to theunofficial bug/issue list.
I had exactly the same problem - I've come up with a workaround which seems to work for me so I thought I'd share in case anybody else would like to implement it (I'm only targetting Internet Explorer as this is for an in house application - so I'm not sure if it will work on other browsers).
The approach I took was to add a LinkButton and added style='display:none;' - I set it's OnClick event to the function that I wanted the CheckBoxList to originally fire - so the LinkButton looks like this:
<
asp:LinkButtonID="LinkButtonCheckBoxListHack"runat="server"OnClick="RedrawGraph">HiddenCheckBoxListHack</asp:LinkButton>This is outside of the UpdatePanel (as is the CheckBoxList).
I then added this to the Triggers collection for the UpdatePanel:
<Triggers><atlas:ControlEventTriggerControlID="LinkButtonCheckBoxListHack"EventName="Click"/></Triggers>I disabled AutoPostBack on the CheckBoxList (CheckBoxListDisplayOptions) and then in the code behind file I had to do the following:
LinkButtonCheckBoxListHack.Style[
"display"] ="none";foreach (ListItem itemin CheckBoxListDisplayOptions.Items)item.Attributes[
"onclick"] =String.Format("{0}.click();", LinkButtonCheckBoxListHack.ClientID);This seems to work well for a static CheckBoxList - if you are databinding then you need to handle the CheckBoxList's OnDataBound event and put the code in there:
protectedvoid CheckBoxListGroups_DataBound(object sender,EventArgs e){
foreach (ListItem itemin CheckBoxListGroups.Items)item.Attributes[
"onclick"] =String.Format("{0}.click();", LinkButtonCheckBoxListHack.ClientID);}
Hope this is of some use until this issue is resolved in future releases. It's not ideal to have to work around such issues but it seems to work well with no adverse side effects that I have noticed!
I've made a small update to this which allows it to work in FireFox as well - this is the update (just one line has changed).
foreach (ListItem itemin CheckBoxListDisplayOptions.Items)item.Attributes[
"onclick"] =String.Format("javascript:setTimeout('__doPostBack(\\'{0}\\',\\'\\')', 0);", LinkButtonCheckBoxListHack.UniqueID);I'm still seeing this in the latest release...is anyone else having an issue with this?
Thanks!
False alarm...I'm actually seeing a different issue for which I will start a new thread.
I can now use a RadioButtonList.SelectedIndexChanged as an asnynchronous trigger for my update panel, but I am having a strange problem. If one of the items in the list is disabled, clicking on any of the items that come after it doesn't cause the async postback (or any postback at all). If all of the items are enabled, clicking on any of the items causes the postback as expected. RadioButtonList ListItems don't have a Visible property, so I have to use the Enabled property.
Any ideas?
In my page .. as a workaround ...i put the radiobuttonlist that i was using as the target... inside its own updatepanel and set it to autopostback = True.
Then by default all other update panels will update when another does if the UpdateMode = "Always". The whole page did not have to postback because it was contained in the update panel.
It may not be the solution for everyone, but it worked for me... and i didnt have to hack in my own javascript.
-Kirb
Maybe this is also a bug in RadioButtonList
I'm using Visual Studio 2005, Ajax (UpdatePanel), a RadioButtonList which updates a DropDownList items.
Html code:
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager
<asp:RadioButtonList ID="rblType" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblType_SelectedIndexChanged" OnPreRender="rblType_PreRender" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="1" Selected="True">National</asp:ListItem>
<asp:ListItem Value="2">International</asp:ListItem>
</asp:RadioButtonList
<asp:UpdatePanel ID="udpChannel" runat="server" ChildrenAsTriggers="False" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlChannel" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlChannel_SelectedIndexChanged"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel
</form>
the RadioButtonList is rendered as:
<span id="rblType">
<input id="rblType_0" type="radio" name="rblType" value="1" checked="checked" />
<label for="rblType_0">National</label>
<input id="rblType_1" type="radio" name="rblType" value="2" onclick="javascript:setTimeout('__doPostBack(\'rblType$1\',\'\')', 0)" />
<label for="rblType_1">International</label>
</span>
You all can notice that the first radiobutton item has no onclick event. So, you're not able to verify if the first radio button item was clicked.
The only way to have a onclick event in the RadioButtonList first item was creating a workaround in behind code:
protected void rblType_PreRender(object sender, EventArgs e)
{
rblType.Items[0].Attributes.Add("onclick","setTimeout('__doPostBack(\\'rblType$0\\',\\'\\')', 0)");
}
I don't know if my approach is correct. Did anyone have the same problem?
Somebody has already try with the new release??
Let us know the issue.
Thx
Hi,
I've still not found a way to have it work with a radiocontrol, but I've made it works with several checkboxes.
Then it's only some code to add the same behavior as radiocontrol to the checkboxes.
If somebody is interested in my solution, let's me know.
Kind regards,
I would be interested to learn.. I would like to have mutually exclusive boxes so If one is selected the other is deselected. I am having a a problem with the radio button to show False or true in the boxes while in edit (detailsvis). I was trying some code to covert to boelan, etc. but it does not realy work. Thanks.
Hi Anna,
did you try theMutuallyExclusiveCheckBox control included in the Ajax Control Toolkit?
No comments:
Post a Comment