`SelectedIndexChanged` it is not firing - c#

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!

Related

Button not firing inside update panel, looked at other questions and none of the fixes work

So, I have this update panel:
<asp:UpdatePanel runat="server" RenderMode="Inline" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ddOutcomeType" />
<asp:AsyncPostBackTrigger ControlID="ddOutcomeCode" />
</Triggers>
<ContentTemplate>
<fieldset>
<asp:DropDownList ID="ddOutcomeType" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddOutcomeType_OnSelectedIndexChanged">
<asp:ListItem Value="0">Please Select...</asp:ListItem>
<asp:ListItem Value="EDU">Continuing in Education</asp:ListItem>
<asp:ListItem Value="EMP">Paid Employment</asp:ListItem>
<asp:ListItem Value="NPE">Not in Paid Employment</asp:ListItem>
<asp:ListItem Value="GAP">Gap Year</asp:ListItem>
<asp:ListItem Value="OTH">Other</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddOutcomeCode" runat="server" DataTextField="COMPDESC"
DataValueField="EBSVALUE"
OnSelectedIndexChanged="ddOutcomeCode_OnSelectedIndexChanged"
AutoPostBack="True" Visible="false" />
<br /><br />
<asp:Label ID="lblDestMessage" runat="server"
Text="Please start typing at least 3 characters of the HE institute
then select from the list (Don't make your own up!)"
Visible="false">
</asp:Label>
<h4 style="align-content:center;">
<asp:Label ID="Label1" runat="server" Text="Comments on Destination">
</asp:Label></h4>
<asp:TextBox ID="txtDestComments" runat="server" Width="70%"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="validJust" runat="server"
Display="Dynamic" ControlToValidate="txtDestComments"
ValidationExpression="^([\S\s]{0,249})$" CssClass="label label-danger"
ErrorMessage="Please enter maximum 250 characters"
SetFocusOnError="True">
</asp:RegularExpressionValidator>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
CssClass="btn btn-primary" OnClick="btnSubmit_OnClick" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
I Have looked at other questions for the same problem but none of the fixes work for this, i tried putting the button outside of the update panel but then the Hidden Fields that are changed by the dropdown lists dont stay changed outside of the update panels.
Any Help?
You are using UpdateMode property of update panel as UpdateMode="Conditional". Either you have to explicitly use Update() method of update panel in button Click event on server side to update the content inside update panel or remove this UpdateMode property because by default it is set as Always.

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).

how to fix the partial rendering if i have three or more drop down lists

If I have three drop down lists:
The second one filled when select from the first one
The third one filled when i select from the second one.
I put the second and third one in update panels to make partial post back but I note that when I select from the second one the third one doesn't fill at all!!
How to fix this problem?
<asp:DropDownList ID="drp_camp" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_camp_SelectedIndexChanged" Width="300px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="drp_fac" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_fac_SelectedIndexChanged"
Width="300px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rVal_fac" runat="server" ControlToValidate="drp_fac"
ErrorMessage="!" InitialValue="-1" ValidationGroup="G1"></asp:RequiredFieldValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drp_camp" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="drp_dep" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_dep_SelectedIndexChanged"
Width="300px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rVal_dep" runat="server" ControlToValidate="drp_dep"
ErrorMessage="!" InitialValue="-1" ValidationGroup="G1"></asp:RequiredFieldValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drp_fac" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Try using cascaded dropdownlist. This works pretty fine which will solve your issue.
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx
You can put all three DropDownLists in one UpdatePanel control, there is no need to try and handle the partial postback of each control.
You could use something like this:
<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<asp:DropDownList ID="drp_camp" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_camp_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="drp_fac" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_fac_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="drp_dep" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drp_dep_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
NOTE: You will need to add your RequiredFieldValidators back in.

Categories

Resources