Why does the whole page do postback and RadioButton loses its value? - c#

I want a selection from a radio button to run a query to populate a DropDownList. I do not want the whole page to do a postback. My whole page is posting back.
Also, when I copy this page to a test page, the value of the radio button is lost. I need the radio button to drive they query which populates the dropdown.
What am I doing wrong which is causing a full postback?
(The method "FillAppointmentTypes_SelectedIndexChanged" is never executed.)
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatePanelToggle" runat="server">
<ContentTemplate>
<div class="form-group">
<label for="radDoctors" class="col-md-3 control-label">
Choose your doctor: <span id="asdf"></span>
</label>
<div class="col-md-9">
<asp:RadioButtonList ID="radDoctors" runat="server" CssClass=""
OnSelectedIndexChanged="FillAppointmentTypes_SelectedIndexChanged"
AutoPostBack="True">
</asp:RadioButtonList>
</div>
</div>
<div class="form-group">
<label for="ddAppointmentTypes" class="col-md-3 control-label">
Reason for Visit: <span id="Span1"></span>
</label>
<div class="col-md-9">
<asp:DropDownList ID="ddAppointmentTypes" runat="server">
</asp:DropDownList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I have tried a trigger inside the updatedatePanel and outside the content template, no love:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="radDoctors" EventName="SelectedIndexChanged" />
</Triggers>

Put...
if(page.ispostback)
{
return;
}
At the top of your page load event..
Hope this helps
Also maybe set the ChildAsTrigger="true" on the updatepanel

Related

DropDownList losing style in UpdatePanel after PostBack in Asp.Net c#

I am using select2 plugin for dropdownlist in asp.net c# which has autopostback true, but when placed in updatepanel its working fine on first page load but when postback happens its styling is gone and dropdownlist is showed in default asp.net format.
<div class="col-md-4 col-12">
<asp:UpdatePanel ID="type" runat="server">
<ContentTemplate>
<div class="form-group">
<div class="controls">
<label for="bktype">Type</label>
<asp:DropDownList ID="bktype" runat="server" CssClass="form-control select2 round" Style="width: 100%" required="" data-validation-required-message="Select a Type" data-placeholder="Select a Type" AppendDataBoundItems="true" AutoPostBack="true" DataSourceID="bk_type" DataTextField="typename" DataValueField="typeId" OnSelectedIndexChanged="bktype_SelectedIndexChanged">
<asp:ListItem Value="">Select a Type</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="bk_type" runat="server" ConnectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\EReader.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [BTypes] ORDER BY [typename]"></asp:SqlDataSource>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="col-md-4 col-12">
<asp:UpdatePanel ID="genre" runat="server">
<ContentTemplate>
<div class="form-group">
<div class="controls">
<label for="bkgenres">Genres</label>
<asp:DropDownList ID="bkgenres" runat="server" ClientIDMode="Static" CssClass="form-control select2 round" multiple="multiple" Style="width: 100%" required="" data-validation-required-message="Select Genres" data-placeholder="Select Genres" AppendDataBoundItems="true">
<asp:ListItem Value="">Select Genres</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Before PostBack
After Postback
After PostBack happens select2 all styleing is gone search box of select2 is also gone. Please help me out.

UpdateProgress fire after first panel update

I have an UpdateProgress associated with an UpdatePanel. The problem is it's not firing until the second update.
Ì have a general UpdatePanel with ID="uppGeneric" and a child one with ID="uppAgrupar" which has a LinkButton inside. When I click on LinkButton it doesn't fire the UpdateProgress bar.
<asp:UpdatePanel ID="uppGeneric" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="row">
<div class="col-md-12 mx-auto">
<br />
<asp:UpdateProgress ID="upCargando" DynamicLayout="true" runat="server" AssociatedUpdatePanelID="uppAgrupar">
<ProgressTemplate>
<div class="progress">
<div class="indeterminate" style="width: 100%"></div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</div>
<div class="row">
<div class="col-md-6 mx-auto">
<asp:UpdatePanel ID="uppAgrupar" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LinkButton ID="btnAgrupar" runat="server" CssClass="el_s btn btn-info btn-block" OnClick="btnAgrupar_Click"><i class="fa fa-search"></i> (S) BUSCAR</asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAgrupar" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
And in code behind I execute (to be sure):
uppAgrupar.Update();
but nothing happens.
I found a partial solution.
The UpdateProgress
<asp:UpdateProgress ID="upCargando" runat="server" AssociatedUpdatePanelID="uppAgrupar">
<ProgressTemplate>
<div class="progress">
<div class="indeterminate" style="width: 100%"></div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
generates the next HTML and CSS:
Which has "display: none;"
The problem is that display attribute was not set up to "display: block;" on first button click.
So, my solution was creating a javascript function that change the display attribute that is fired on the event "onClientClick".
<asp:LinkButton ID="btnAgrupar" runat="server" CssClass="el_s btn btn-info btn-block" OnClientClick="activar_barra()" OnClick="btnAgrupar_Click"><i class="fa fa-search"></i> (S) BUSCAR</asp:LinkButton>
and the javascript function is (it could access by ClientID but it's the same result)
function activar_barra()
{
document.getElementsByClassName('progress')[0].parentNode.style.display = "block";
}

TextBox returns empty String on Button click in Bootstrap modal

Might be a dummy question, but this issue is getting me mad.
I have a MasterPage that has the main design and of course the <form runat="server"> tag.
The page I'm currently working on has a bootstrap modal containing a text box and button. I want to get the TextBox text entered by the user in the "OnClick" event of the Button. At first button click event wasn't fired so I used Use UseSubmitBehavior="False" and the click event is fired finally. Here's the problem, the TextBox returns empty string when I try to get the text in it.
My page's html code :
<div id="dlgNewOrder" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<div>
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div class="container">
<div class="row">
<div class="col-md-3">
<asp:TextBox runat="server" CssClass="form-control" EnableViewState="True" ID="txtQuantity" placeholder="Quantity"></asp:TextBox>
</div>
</div>
</div>
<div>
<br />
</div>
<br />
<asp:Button runat="server" ID="btnAddToCart" UseSubmitBehavior="False" Text="Add" CssClass="btn btn-info" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</div>
And here's the code behind :
void btnAddToCart_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtQuantity.Text))
{
lblErrorMessage.Text = "Error";
}
else
{
lblErrorMessage.Text = "Correct";
}
}
Seems to be as issue for ASP.NET web forms UpdatePanel with the bootstrap modal.
I tried the jQuery modal and works like a charm! :s

asp.net Panel visibility in an Update Control

I am creating a mobile menu style function.
An image button is clicked and it should show the menu if the menu is currently not shown, and hide it if the menu is currently shown.
<div class="menuicon">
<asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" />
<asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" />
</div>
<div class="menulist">
<asp:Panel ID="panMenuContainer" runat="server">
<ul>
<li>
Login
</li>
</ul>
</asp:Panel>
</div>
the menubtn Click event:
if(hdfMenuStatus.Value == "menudown")
{
panMenuContainer.Visible = true;
hdfMenuStatus.Value = "menuup";
}
else
{
panMenuContainer.Visible = false;
hdfMenuStatus.Value = "menudown";
}
This works absolutely fine, but as soon as I encase the menuicon and menulist divs in an update panel then it stops working:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="menuicon">
<asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" />
<asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" />
</div>
<div class="menulist">
<asp:Panel ID="panMenuContainer" runat="server">
<ul>
<li>
Login
</li>
</ul>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I also put the menubtn outside the update panel with an Async Trigger but that didn't work either.
<div class="menuicon">
<asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" />
<asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" />
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="menulist">
<asp:Panel ID="panMenuContainer" runat="server">
<ul>
<li>
Login
</li>
</ul>
</asp:Panel>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="menubtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Having a page postback just to show or hide the menu seems entirely unsatisfactory.
Can anybody suggest what might fix this? I'm sure I've had Panel Visibility working inside an Update Panel before.
What happens when you change your UpdatePanel to look like he following
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="tsm" runat="server"></ajaxToolkit:ToolkitScriptManager>
<div>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
</div>
....the rest of your code etc..
I would need to see what the rest of your html markup looks like but I just tested this with and without the <ajaxToolkit:ToolkitScriptManager> and the UpdatePanel enclosed inside the form tag, and it works..
You need to change some of your code as example.
<div class="menuicon">
<asp:ImageButton ID="menubtn" ImageUrl="~/assets/menu.png" OnClick="menubtn_Click" runat="server" />
<asp:HiddenField ID="hdfMenuStatus" runat="server" Value="menudown" />
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="menulist">
<asp:Panel ID="panMenuContainer" runat="server">
<ul>
<li>
Login
</li>
</ul>
</asp:Panel>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="menubtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

FileUpload Full Postback Issue Under Double UpdatePanels

<asp:UpdatePanel runat="server"><ContentTemplate>
<asp:UpdatePanel ID="PanelImportFileForCSV" Visible="false" runat="server">
<ContentTemplate>
<div class="form-group" runat="server">
<label for="textfield" class="control-label col-sm-4">CSV File<span class="ErrorMessage" style="color: red;"> *</span>/label>
<div class="col-sm-8">
<asp:FileUpload runat="server" ID="FileUpload2" /> <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator2" ControlToValidate="FileUpload1" ForeColor="DarkRed" ErrorMessage="Only (.mpp) File is allowed" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.csv|.CSV)$" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate
</asp:UpdatePanel>
<div class="row">
<div class="col-sm-12">
<div class="form-actions">
<asp:button id="btnProceed" runat="server" CssClass="btn" ToolTip="Cancel" Text="Proceed" OnClick="btnProceed_Click" CausesValidation="False"></asp:button>
</div>
</div>
</div>
I know I should use trigger for Full postback for file upload, but i have multiple updatepanels and that idea is not working anymore!
Kindly Help me
Nvm i have fixed the issue by adding the following line in page_Load()
Page.Form.Attributes.Add("enctype", "multipart/form-data")

Categories