UpdatePanel not refreshing on my radiobuttonlist - c#

I have some radio buttons like this:
<li class="list-group-item">
<p>YOUR AGE IS AN IMPORTANT FACTOR IN YOUR ABILITY TO TAKE ON INVESTMENT RISK. YOUR AGE IS:</p>
<asp:RadioButtonList ID="radioBtnFirst" CssClass="radioBtnAge" runat="server" RepeatDirection="Horizontal"
TextAlign="Right" AutoPostBack="True" OnSelectedIndexChanged="radioBtnFirst_SelectedIndexChanged">
<asp:ListItem Value="1">60 and over</asp:ListItem>
<asp:ListItem Value="2">50 - 59</asp:ListItem>
<asp:ListItem Value="3">40 - 49</asp:ListItem>
<asp:ListItem Value="4">30 - 39</asp:ListItem>
<asp:ListItem Value="5">Under 30</asp:ListItem>
</asp:RadioButtonList>
</li>
Now somewhere donw I have a textbox where I want to get the value of the selected radiobutton. This is the code that is doing that:
protected void radioBtnFirst_SelectedIndexChanged(object sender, EventArgs e)
{
totalScore.Text = radioBtnFirst.SelectedValue;
}
I wanted to add UpdatePanel so it won't refresh the whole page but it's not working, when I press first one of the radio buttons it doesn't happen anything, but when I press the second time, it refreshes again the whole page.
This is the code that I used for UpdatePanel:
<h3>Total Score:</h3>
<asp:UpdatePanel ID="upScore" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server" ID="totalScore" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="radioBtnFirst" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>

Now it's ok, it's working. I figured out that the problem was behind the code in Page_Load method.

Related

OnSelectedIndexChanged not working within the asp:updatePanel

I have a dropdown in which list of countries will be listed.During the select OnSelectedIndexChanged event country code such as +91 will be shown in a textbox. The dropdown should be in <asp:Update panel> tag and the update panel just working fine. OnSelectedIndexChanged event also working in the code behind. but the problem is the country code value not displayig in the textbox.
Here is my code..
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:DropDownList
runat="server"
ID="ddl_country"
AutoPostBack="true"
OnSelectedIndexChanged="ddl_country_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator
ControlToValidate="ddl_country"
ID="reqCountry"
ValidationGroup="req"
class="validation-msg"
ErrorMessage="Please select a country"
InitialValue="0"
runat="server"
Display="Dynamic">
</asp:RequiredFieldValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="ddl_country"
EventName="ddl_country_SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:TextBox runat="server" ID="text_countrycode"/>
text_countrycode is outside any update panel in the code above. So it's in the form and the entire form needs to post back for this to change it's text.
You're probably using Updatepanels because you don't want the entire form to flash and post back.
Changing the dropdown list doesn't refresh the entire page because it's in an Update Panel. If you want the Textbox to be updated without an whole page post back, put it in it's own updatepanel and trigger it from the first one.
Or even easier, just put them together in the same one.
Add Textbox Control Inside the <ContentTemplate>.
Try this code :
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddl_country" AutoPostBack="true"
OnSelectedIndexChanged="ddl_country_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="ddl_country" ID="reqCountry"
ValidationGroup="req" class="validation-msg" ErrorMessage="Please select a country"
InitialValue="0" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="text_countrycode"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl_country" EventName="ddl_country_SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>

`SelectedIndexChanged` it is not firing

I have a DropDownList and I have a <DIV> element, When I change the value of dropdown my div is not going to show up I have the following ascx code
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true">
<asp:ListItem Value="Zgjidh Kompaninë">-- Zgjidh Kompaninë--</asp:ListItem>
<asp:ListItem Value="Meridian Corporation">Meridian Corporation</asp:ListItem>
<asp:ListItem Value="Meridian Express">Meridian Express</asp:ListItem>
<asp:ListItem Value="Buka">Buka</asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="chart_div"></div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
If I place this <div id="chart_div"></div> outside of UpdatePanel it works or If I just delete the <Triggers> tag it works but it refreshes the page both times. So Why My Div Is Not Showing UP I need hep please
I am working on a sharepoint WebPart!

How to prevent UpdatePanel from resetting values outside the panel?

Here is my problem :
I select a type using ddlType
I click on btnAddChoice to add a few choices
I click on btnSubmit to save the form
But when I try to get ddlType.SelectedValue in btnSubmit_Click(), it's always back to "Select a type".
If I don't do step #2 then it works fine.
From what I understand, the problem is related the ajax call (postback) and could be solved by saving the SelectedValue in the Session or ViewState.
But I have many many other controls (such as ddlType) on this page so it does not seem like an elegant solution. I was hoping for the framework to keep the selected values in the ViewState automatically ... Any idea ? After all, is it not the goal of UpdatePanel to update just the panel ?
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="ddlType" runat="server">
<asp:ListItem Text="Select a type" Value=""></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="Two" Value="2"></asp:ListItem>
<asp:ListItem Text="Three" Value="3"></asp:ListItem>
</asp:DropDownList>
<div>
<strong>Choices</strong>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddChoice" EventName="Click" />
</Triggers>
<ContentTemplate>
<ul class="list-unstyled">
<asp:PlaceHolder runat="server" ID="phChoices"></asp:PlaceHolder>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnAddChoice" runat="server" Text="Add Choice" CausesValidation="false"
OnClick="btnAddChoice_Click" />
</div>
<asp:Button ID="btnSubmit" runat="server" Text="Add question"
OnClick="btnSubmit_Click" />
UPDATE
Part of the problem was caused by :
$('#<%= MainPanel.FindControl("btnAddChoice").ClientID %>').click(function () {
var ddlType = $('#<%= MainPanel.FindControl("ddlType").ClientID %>');
ddlType.attr('disabled', 'disabled');
});
Please see this question for details.
Regarding other controls also empty, the reason is that "dynamically created controls have to be created each and every post-back"
Try adding something like this to your ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
Then all the code which you want to get refreshed will come under Update Panel
<asp:Updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
...All your HTML content here
</ContentTemplate>
</asp:Updatepanel>
Hope that helps
More information on EnablePartialRendering
UPDATE
Also if your dropdownlist value is not getting saved because of Updatepanel
try Request.Form and check
Request.Form.Get("dropdownlistID").ToString());

Radio Button List Selection and postback of the page

In my program I have used upadate panel nad ScriptManager. My problem is,I am using radio button named RbFresh, It have two values named Fresher and Experienced when I select Experienced I will show a panel on this panel I have put text box control .But after selection any value in radionbutton total page will be full postbacks.How will avoid full postback of my page.
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RbFresh" runat="server" onselectedindexchanged="RbFresh_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="297px" AutoPostBack="True">
<asp:ListItem Text="Fresher" Value="1"></asp:ListItem>
<asp:ListItem Text="Experienced" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
<Triggers>
<asp:PostBackTrigger ControlID="Rbfresh"/>
</Triggers>
Using this code page will not be post back and you can easily get the value of radio buttons
Paste on HTML Page
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RbFresh" runat="server" onselectedindexchanged="RbFresh_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="297px" AutoPostBack="True">
<asp:ListItem Text="Fresher" Value="1"></asp:ListItem>
<asp:ListItem Text="Experienced" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
Paste on .cs Page
protected void RbFresh_SelectedIndexChanged(object sender, EventArgs e)
{
int Value = 0; int.TryParse( RbFresh.SelectedValue,out Value);
int ID = Value;
}

asp.net drop down list selectedindexchanged firing slowly compared to button click within update panel

I have a few buttons within an update panel. I have now been asked to replace the buttons with
a drop down list . I see that the selectedindexchanged event on the drop down list is much slower
than the button click event. I have the code below. Can anyone point me as to why it is happenning ?
or what I can do to make the selectedindexchanged event response faster .
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<div class="ui-widget-header" style="display: inline;">
<asp:Label ID="lblRefresh" runat="server" Text="Refresh Interval:" CssClass="label"
ForeColor="Black"></asp:Label>&nbsp&nbsp&nbsp
<asp:LinkButton ID="btnOFF" runat="server" OnClick="btnOFF_Click" Text="Off">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn60SEC" runat="server" OnClick="btn60SEC_Click" Text="1Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn5MIN" runat="server" OnClick="btn5MIN_Click" Text="5Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn10MIN" runat="server" OnClick="btn10MIN_Click" Text="10Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn15MIN" runat="server" OnClick="btn15MIN_Click" Text="15Min">
</asp:LinkButton>
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlRefresh" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Well what seems to work for me right now is to set AutoPostback = "true" for the dropdownlist .
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
I had the same problem and I found that the problem is with _destroyTree. Check it here (https://siderite.dev/blog/very-slow-updatepanel-refresh-when.html).

Categories

Resources