Frens,
i have a textbox with ajaxToolkit:CalendarExtender which losses data when i chose radio buttons ....
please read my code...
<asp:UpdatePanel ID="uppnl_Select_File_Format" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="input-field-box-container">
<asp:TextBox ID="txtExpiryDate" runat="server"
SkinID="FormInputTextBox" ReadOnly="true"
ValidationGroup="PublishUser"> </asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ajax_Expiry_Date" runat="server" TargetControlID="txtExpiryDate">
</ajaxToolkit:CalendarExtender>
</div>
<div class="input-field-box-container">
<asp:RadioButton ID="rbtnEnabled" GroupName="Print" Text="Enable" runat="server"
AutoPostBack="true"
OnCheckedChanged="rbtnEnabled_CheckedChanged" CssClass="checkbox-auto"
Width="220px" />
<asp:RadioButton ID="rbtnDisabled"
GroupName="Print" Text="Disable" runat="server"
AutoPostBack="true" OnCheckedChanged="rbtnDisabled_CheckedChanged" CssClass="checkbox-auto"
Width="220px" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnCreate" />
<asp:AsyncPostBackTrigger ControlID="ajax_Expiry_Date" />
</Triggers>
</asp:UpdatePanel>
Your radioButton's AutoPostback attribute(or what it is called) is true that means when you change the choice of radio button the page will post back and which will cause to refresh the UpdatePanel.As long as your radio button and CalenderExtender is on the same UpdatePanel every time OnCheckedChanged="rbtnDisabled_CheckedChanged" works CalenderExtender will loose data.
Well you can understand that your solution is using different UpdatePanels for those RadioButtons and CalenderExtenders.
The solution I arrived at was to remove ReadOnly="true".
Related
<form runat="server" id="from1">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<script src='https://www.google.com/recaptcha/api.js'></script>
<asp:Panel runat="server" ID="pnlSiteQuestions">
>>>>> CONTROLS removed for brevity <<<<<
<asp:Button ID="btnContinue" runat="server" Text="Continue" OnClick="btnContinue_Click" ValidationGroup="Questions" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlNotRequired" runat="server" Visible="false">
Sorry you do not qualify.
</asp:Panel>
<asp:Panel runat="server" ID="pnlAdditionalDetails" Visible="false">
<asp:ValidationSummary runat="server" ID="ValidationSummary1" />
Name
<asp:RequiredFieldValidator runat="server" ID="ValidatorName" ControlToValidate="ContactFormNameTextBox" ErrorMessage="Name is required" CssClass="ErrorClass">Required</asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="txtName" />
<div class="g-recaptcha" data-sitekey="ABC123"></div>
<asp:Button runat="server" ID="button1" Text="Confirm" OnClick="button1_Click" />
</asp:Panel>
</form>
I have the above form and decided to add an update panel. When a user clicks Continue, it goes to a database and determines if the user qualifies. If not pnlNotRequired message is displayed otherwise pnlAdditionalDetails is displayed.
Everything is/was working until i added the update panel. So removing the UP has everything working.
I tried adding a trigger but i didnt fully understand how it should be configured as i dont completely understand why this is occurring?
No Javascript errors listed either. Anyway to overcome this issue?
Update panel should cover all panels. Add property to update panel "UpdateMode='Conditional'" than add trigger block
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.
My problem is that I can't seem to get my textbox to fire the OnTextChanged event. I also checked and it doesn't seem like it is doing an autopostback despite the fact that it is set to true.
Basically, I am trying to validate the text in the textbox and either enable or disable a button based on the validation status.
Here's my code:
<asp:Panel ID="panelAccessControl" runat="server" Visible="false">
<asp:Panel ID="panelAddMileageRate" runat="server" BorderWidth="2" >
<h2>Add Mileage Rate</h2>
<asp:ScriptManager ID="scriptManagerMileageRate" runat="server" />
<asp:UpdatePanel ID="updatePanelAddMileageRate" runat="server">
<ContentTemplate>
<p>
Purpose:
<asp:DropDownList ID="ddlAddPurpose" runat="server"
AutoPostBack="true" Width="200px"></asp:DropDownList>
<br />
Country:
<asp:DropDownList ID="ddlAddCountry" runat="server"
AutoPostBack="true" Width="200px" >
</asp:DropDownList>
<br />
Effective Date:
<asp:Calendar ID="calAddEffectiveDate" runat="server">
</asp:Calendar>
<br />
Mileage Rate:
<asp:TextBox ID="txtAddMileageRate" runat="server"
AutoPostBack="true" Width="200px"
CausesValidation="true"
ontextchanged="txtAddMileageRate_TextChanged">
</asp:TextBox>
<asp:RegularExpressionValidator
ID="validatorAddMileageRate"
ControlToValidate="txtAddMileageRate" runat="server"
SetFocusOnError="true"
ErrorMessage="Only Numbers allowed"
ValidationExpression="^\d{1,20}(\.\d{0,4})?$">
</asp:RegularExpressionValidator>
</p>
</ContentTemplate>
</asp:UpdatePanel>
<p>
<asp:Button ID="buttonAddSecurityGroup" runat="server"
Text="Submit" onclick="buttonAddSecurityGroup_Click" />
</p>
</asp:Panel>
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
</asp:Panel>
The text box in question is txtAddMileageRate.
Set the EventName property for your txtAddMileageRate AsyncPostBackTrigger to TextChanged.
Add following codes inside your update panel and outside of ContentTemplate
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtAddMileageRate"
EventName="TextChanged" />
</Triggers>
Other sugguestion:
Have you tried looking at the AutoComplete (http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete) control that is part of the AjaxControlToolKit? Its behaves the same way you want your solution to behave.
I'm running into a bit of an issue. I have some asp.net controls wrapped in an update panel, but when I click the submit button it jumps to the top of the page. I've read a bunch of posts on here, and they either require use of some javascript or say set the MaintainPagePostion to "true" in the page directive. I tried setting it to true, that did not work. I really don't want to use a javascript script to accomplish this either. I was under the impression that this is one of the benefits to using an update panel. However, the part that I find most confusing, is it used to not do this. I don't remember changing anything on the website that would have caused this. Any help with this problem is appreciated. Thanks.
Here is the code I'm using.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="pnlEmailStuff" runat="server">
Name: <asp:TextBox ID="txtName" runat="server" Width="202px"></asp:TextBox><br />
Email: <asp:TextBox ID="txtEmail" runat="server" Width="203px"></asp:TextBox><br />
<span style="font-size:12px; font-weight:normal; margin-left:55px;">**Please double check email**</span><br />
Message:<br />
<asp:TextBox ID="txtMessage" runat="server" Width="370px" TextMode="MultiLine" Font-Names="Tahoma" Font-Size="Small" Height="75px"></asp:TextBox><br />
<asp:Label ID="lblEmailError" runat="server" Text="" Font-Size="Small" ForeColor="Red"></asp:Label>
<asp:ImageButton Height="25px" Width="60px" CssClass="EmailSubmit" ImageUrl="Images/MailingListBtnSubmit2.png" ID="btnSubmit" runat="server" onclick="btnSubmit_Click"/>
</asp:Panel>
<asp:Panel ID="pnlThankYou" runat="server" Visible="false">
<p style="text-align:center; font-size:30px;">Thank you!<br /><span style="font-size:20px;">Your Email has been sucessfully submitted.</span></p>
</asp:Panel>
</ContentTemplate>
You can do it in 4 ways :
From Code-behind - Page.MaintainScrollPositionOnPostBack = true;
From Page Directive - MaintainScrollPositionOnPostback="true"
From Web.config - <pages maintainScrollPositionOnPostBack="true" />
Using Javascript. You can use the code from following link. It worked for me -
http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx
I think, it's not jump to the top of the page. It's refreshing the page. What's your update panel's UpdateMode? Is it Conditional? If it's conditional, check trigger. ControlID should be button ID and EventName='Click'. Then check the area of Update Panel .
Sample Code Here :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlEmailStuff" runat="server">
Name: <asp:TextBox ID="txtName" runat="server" Width="202px"></asp:TextBox><br />
Email: <asp:TextBox ID="txtEmail" runat="server" Width="203px"></asp:TextBox><br />
<span style="font-size:12px; font-weight:normal; margin-left:55px;">**Please double check email**</span><br />
Message:<br />
<asp:TextBox ID="txtMessage" runat="server" Width="370px" TextMode="MultiLine" Font-Names="Tahoma" Font-Size="Small" Height="75px"></asp:TextBox><br />
<asp:Label ID="lblEmailError" runat="server" Text="" Font-Size="Small" ForeColor="Red"></asp:Label>
<asp:ImageButton Height="25px" Width="60px" CssClass="EmailSubmit" ImageUrl="Images/MailingListBtnSubmit2.png" ID="btnSubmit" runat="server" onclick="btnSubmit_Click"/>
</asp:Panel>
<asp:Panel ID="pnlThankYou" runat="server" Visible="false">
<p style="text-align:center; font-size:30px;">Thank you!<br /><span style="font-size:20px;">Your Email has been sucessfully submitted.</span></p>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Have you specified the triggers in the update panel? If you specify the triggers in the triggers section then the update panel will update without jumping on top.Also you need to give updatemode = "conditional". It can be done like this:
<asp:UpdatePanel ID="ex" runat="server" UpdateMode="Conditional">
<ContentTemplate>
//your controls here
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="yourbuttonid" />
</Triggers>
</asp:UpdatePanel>
Well thank you to everyone that gave me suggestions. As it turns out the Page Routing is what caused this issue. So all I had to do to get it working was add and ignore line for that page in my RegisterRoutes code block:
void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("Mobile");
routes.Ignore("Booking.aspx*");//<---- This Fixed it.
routes.MapPageRoute("Gallery", "Gallery/{Name}", "~/Gallery.aspx");
routes.Ignore("*");//<---- This is better for me. It acts as a catch all.
}
This helped me solve the issue: http://forums.asp.net/t/1743640.aspx
EDIT
I added the "routes.Ignore("");" code to it to act as a catch all, so I really don't need to ignore "Booking.aspx" specifically. Keep in mind though the order is important here. The Ignore("") needs to be the last one or else none of the other routing will work.
Thanks again Everyone.
Please try PageRequestManager handlers
<script>
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
try {
sender._controlIDToFocus = null;
}
catch (e) {
}
}
</script>
I was stuck for a few hours with a similar problem. I was convinced the problem was the UpdatePanel but it ended up being the defaultfocus & defaultbutton attributes in the form tag that was causing the page to jump up to focus the first textbox at the top of the page.
<form id="form1" runat="server" defaultbutton="buttonId" defaultfocus="textboxId">
This is something else to look at when facing this kind of issue.
I have two update panels on a page. And I want to update both of them conditions at different-2 conditions. But I don't know why this is not happening. I have specified triggers for both but not helpful, below is my code.
Please let me know Where I am wrong.
Actually there are three dropdown lists in first update panel when their selectedindexchange is fired then the second update panel's content also updates.
<asp:UpdatePanel ID="upSearch" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div style="float: left; width: auto;">
<asp:DropDownList ID="ddlLocation" runat="server" Width="206px" DataTextField="LocationName"
DataValueField="Locationid" AutoPostBack="true" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlArea" runat="server" Width="200px" DataTextField="AreaName"
DataValueField="Areaid" AutoPostBack="true" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlRoom" runat="server" Width="200px" DataTextField="RoomName"
DataValueField="Roomid">
</asp:DropDownList>
</div>
<div style="float: left; width: 80px;">
<asp:Button ID="btnSearch" runat="server" Text="Search" ValidationGroup="vgSearch"
CssClass="bluebtn" UseSubmitBehavior="false" OnClick="btnSearch_Click" />
</div>
<div style="float: left; width: 99%; padding: 5px 0px;">
</div>
</ContentTemplate>
</asp:UpdatePanel>
And the second one is as follow:-
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Calendar ID="calSchedule" runat="server" NextPrevFormat="FullMonth" OnDayRender="calSchedule_DayRender"
OnVisibleMonthChanged="calSchedule_VisibleMonthChanged">
<DayHeaderStyle CssClass="dayheaderStyle" />
<NextPrevStyle />
<OtherMonthDayStyle BackColor="#ffffff" />
<SelectedDayStyle />
<TitleStyle CssClass="titleStyle" />
<TodayDayStyle BackColor="#ffffa0" ForeColor="#6699cc" />
<WeekendDayStyle />
<DayStyle CssClass="dayStyle" />
</asp:Calendar>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
First of all I would like to recall the use of UpdateMode
Always The panel will update its content on every post on the page, they can be partial rendering posts or full posts, in both cases the content of the panel will be updated
Conditional The content of the panel will only be updated when different conditions are met:
By default the events triggered by its child objects will trigger an update, you can change this behavior setting ChildrenAsTriggers="false"
When you declare a trigger in the Triggers section of the UpdatePanel
When you explicitly call the UpdatePanel.Update() method
Full page posts will trigger the update
The following code does the following:
Each UpdatePanel is updated when its child controls raise an event
The UpdatePanel 1 named: up1 will be updated only when its child controls raise an event
The UpdatePanel 2 named up2 will be updated when its child controls raise an event
The UpdatePanel 2 named up2 will also be updated when the triggers defined are fired, in this case, when the DropDownList named ddl1OnPanel1 on the UpdatePanel 1 fires its SelectedIndexChanged
The UpdatePanel 2 named up2 will also be updated when the DropDownList named ddl2OnPanel1 on the UpdatePanel 1 raises its SelectedIndexChanged, because in code it explicitly calls: this.up2.Update();
I think that tweaking this code, you could achieve your desired goal, just copy paste it on a new page and run it
Check the following code (see how the labels showing the date are affected in different ways depending on the events raised):
Code Behind
protected void ddl1OnPanel1_SelectedIndexChanged(object sender, EventArgs e)
{
this.lblMessageOnPanel1.Text = "From ddl1 " + DateTime.Now.ToString();
this.calendarOnPanel2.SelectedDate = DateTime.Today.AddDays(1);
this.lblMessageOnPanel2.Text = "From ddl1 " + DateTime.Now.ToString();
}
protected void ddl2OnPanel1_SelectedIndexChanged(object sender, EventArgs e)
{
this.lblMessageOnPanel1.Text = "From ddl2 " + DateTime.Now.ToString();
this.calendarOnPanel2.SelectedDate = DateTime.Today.AddDays(2);
this.lblMessageOnPanel2.Text = "From ddl2 " + DateTime.Now.ToString();
this.up2.Update();
}
ASPX
<asp:ScriptManager runat="server" ID="scriptManager" />
<asp:Button Text="Full Post" runat="server" />
<br />
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddl1OnPanel1" AutoPostBack="true" OnSelectedIndexChanged="ddl1OnPanel1_SelectedIndexChanged">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
<br />
<asp:DropDownList runat="server" ID="ddl2OnPanel1" AutoPostBack="true" OnSelectedIndexChanged="ddl2OnPanel1_SelectedIndexChanged">
<asp:ListItem Text="text3" />
<asp:ListItem Text="text4" />
</asp:DropDownList>
<br />
<asp:Label runat="server" ID="lblMessageOnPanel1" />
<br />
<asp:Button ID="Button1" Text="text" runat="server" />
<br />
On every post on Panel 1: <%:DateTime.Now %>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<asp:UpdatePanel runat="server" ID="up2" UpdateMode="Conditional">
<ContentTemplate>
<asp:Calendar ID="calendarOnPanel2" runat="server" >
<DayHeaderStyle CssClass="dayheaderStyle" />
<NextPrevStyle />
<OtherMonthDayStyle BackColor="#ffffff" />
<SelectedDayStyle />
<TitleStyle CssClass="titleStyle" />
<TodayDayStyle BackColor="#ffffa0" ForeColor="#6699cc" />
<WeekendDayStyle />
<DayStyle CssClass="dayStyle" />
</asp:Calendar>
<br />
<asp:Label ID="lblMessageOnPanel2" runat="server" />
<br />
On every post On Panel 2: <%:DateTime.Now %>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl1OnPanel1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Simple Output
You could change the UpdateMode="Always" on the UpdatePanel 2, to see the difference, if you do it, this panel will be updated on every post, either full posts or posts coming from the UpdatePanel1
I used this successfully for 4 updatepanel.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization="true" CombineScripts="false" ScriptMode="Release">
</asp:ToolkitScriptManager>
Remove the Autopostback="True" from the DropdownLists if you want an asyncpostback to happen.
Also, what exactly is wrong at the moment? The updatepanels don't update at all?
EDIT. Also remove childrenAsTriggers as it is not needed at this occasion
If you are using nested update panels refer below sample code:
<asp:UpdatePanel id="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<fieldset>
<legend>Parent UpdatePanel</legend>
Last refresh <%=DateTime.Now.ToString() %> <br />
<asp:Button ID="Button1" runat="server" Text="Refresh Outer Panel" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<fieldset>
<legend>Nested UpdatePanel</legend>
Last refresh <%=DateTime.Now.ToString() %> <br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
If not using nested update panels then remove "UpdateMode" conditions from both Updatepanels of your code.