Calendar control without postback - asp.net

I notice the calendar control in ASP.NET does not have an AutoPostBack property. I want that when I select a date from the control, the control must not post back the page. How do I do that?and one thing more when i hover over on the calender it shows me a script. "javascript:__doPostBack('Calendar2','5098')". So my question is how to disable this javascript to don't postback the values

There is no way to turn off the postbacks to the server but you can use updatepanel control which can help you some what.

According to PLBlum at the ASP.NET forums:
The Calendar control included with ASP.NET uses postbacks only. If you
added Microsoft ASP.NET AJAX to the page and put the calendar into an
UpdatePanel, it can reduce the appearance of postbacks by using
callbacks. But it still makes a trip to the server for each click on a
date or month.
Many people have created replacements to the Calendar control that
uses javascript to do the work. I am the author of one, in "Peter's
Date Package". You can locate others in these sites: the Control
Gallery (here under Resources), www.123aspx.com, and www.411asp.net.

You can add like following
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Calendar ID="ad_Cal" runat="server" OnSelectionChanged="ad_Cal_SelectionChanged" ></asp:Calendar>
<asp:Button ID="btn_Del_Day" runat ="server" Text ="Remove Day" OnClick="btn_Del_Day_Click" UseSubmitBehavior="False" BackColor="#4AA3DF" Font-Bold="True" ForeColor="White" />
<asp:Button ID="btn_sort_Date" runat="server" Text="Sort Days" UseSubmitBehavior="False" BackColor="#4AA3DF" Font-Bold="True" ForeColor="White" OnClick="btn_sort_Date_Click" />
<asp:ListBox ID="lst_ad_dates" runat="server"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
notice that you should use UseSubmitBehavior="False" with buttons also to stop postback for buttons in the same updatePanel
It works fine

I think you can use "CalendarExtender" from AjaxToolkit
<asp:TextBox ID="txtCalendarExtender" runat="server"></asp:TextBox>
<cc3:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtCalendarExtender" Format="dd/MM/yyyy">
</cc3:CalendarExtender>
Remember to add this code at the top of your page:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc3" %>

Related

ASP.NET update panel nested refreshing

This code is in a user control . and i am providing a sample code structure to get an overview .
<Update Panel UpdateMode= "Conditional">
<panel></panel>
<panel>
<button></button>
</panel>
<updatepanel UpdateMode="Conditional"></updatepanel>
</Updatepanel>
so when i click a button in the second panel , i am supposed to hide that panel and it is happening but simultaneously the other panels are getting refreshed . what could be the possible reason for that ?
Based on the code snippet you may have a couple issues to fix:
Make sure you have a ScriptManager on the page with EnablePartialRendering="true"
Correct your markup by making the <UpdatePanel> elements ASP.NET UpdatePanel controls by prefixing them with "asp:".
Add UpdateMode="Conditional" to both of your UpdatePanel controls
Move the sections you want to update asynchronously into the UpdatePanel controls.
Example
<asp:ScriptManager ID="MyScriptManager" EnablePartialRendering="true" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="MyUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="This is a label!"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Click Me" />
</ContentTemplate>
</asp:UpdatePanel>
The following article is a great resource to learn more about the UpdatePanel with details on it's capabilities.
Understanding Partial Page Updates with ASP.NET AJAX

tracking variable values in asp.net ajax user control

Working on an asp.net page I created a custom ajax web user control that displays the contents of a list value (which is loaded via database calls). The control includes "next" and "previous" buttons, as well as a couple text boxes. My initial version used a session variable (iterator) to keep track of where the user is while clicking the buttons and filling the text boxes with values from the List[].
In my next iteration, I need to be able to use this custom control, which will be presented many times in a table (or more probably grid), but I'm having trouble figuring out how to handle the iterator, since the session variable will obviously no longer work.
Does anyone have a suggested approach, or a recommended article?
I solved the problem by creating a second form on my user control that is segregated from the controls contained within the UpdatePanel. Before those controls are refreshed, the segregated control (a label in this case) is programmatically assigned a value and when the control Page_Load event fires it references the segregated label value to keep track of it's current position. I also had to move the ScriptManager out of my control and place it on the page(s) the control will be used on, since there will be several of these custom user controls on the page and only one ScriptManager is permitted per page.
<form id="NaviControl" >
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Panel ID="controlsPanel" runat="server" HorizontalAlign="Center" >
<asp:Panel ID="Panel1" runat="server" >
<asp:Button ID="btnLast" runat="server" Text="Previous" Height="25px" Width="75px" OnClick="btnLast_Click" />
<asp:TextBox ID="tbStatusCode" runat="server" ></asp:TextBox>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="Center" >
<asp:TextBox ID="tbDescription" runat="server" ></asp:TextBox>
<asp:Button ID="btnNext" runat="server" Text="Next" Height="25px" Width="75px" OnClick="btnNext_Click" />
</asp:Panel>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
<form>
<asp:Label ID="lblCounter" runat="server" visible="false" />
</form>
Hope some other nubs find this approach useful.

FileUpload, UpdatePanel and ModalPopupExtender

I am trying to use a FileUpload control in a ModalPopupExtender in an UpdatePanel.
I have set a trigger for my Upload button, so that it does a full postback.
What happens is that after the full postback, all the ModalPopupExtenders that I have in the page show up one after the other at the bottom of my page, rah
I've tried using the AsyncFileUpload control, but have not been able to get the UploadEvent to fire, have tried everything I could find in Google. Decided to stick with the FileUpload control.
<ajaxToolkit:ModalPopupExtender ID="MPEBannerImage" runat="server" TargetControlID="btnBannerImage" PopupControlID="pnlBannerImage" Y="200">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlBannerImage" runat="server" Width="530px" >
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:ImageButton ImageUrl="btn-UploadFile.png"
ID="btnUpload" runat="server" OnClick="btnUpload_Click" />
</asp:Panel>

getting null path while uploading image upload in .net

I have used file upload control of asp.net but I am getting empty string while saving.my code-
<asp:FileUpload ID="fuProductLogo" runat="server" CssClass="file paddBottom5px" />
.cs code is-
if (fuProductLogo.PostedFile != null && fuProductLogo.PostedFile.ContentLength > 0)
{
...
}
but the .PstedFile and .CountLength is coming zero but the same code is working fine in another page.Please help.
There are several things to check here:
as #williem said, remove updatepanel from the form if you are using it
add enctype="application/x-www-form-urlencoded" in the form tag
Please remember to update your post after your code modifications and checks.
If the FileUpload is in an UpdatePanel it will be cleared on each ajax-postback. You can use multiple UpdatePanels around the FileUpload control and keep the FileUpload out of them. Also make sure that the button that triggers the actual upload does a real postback, not an asyncpostback. Do this by adding the button to the PostbackTrigger of it's UpdatePanel or by taking it out of the UpdatePanel.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
<asp:Button ID="Submit" runat="server" Text="Submit" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Submit" />
</Triggers>
</asp:UpdatePanel>
You can also use an AsyncFileUpload control from the Asp.net Ajax Toolkit, it works inside an UpdatePanel but it is a little harder to get this to work.

Checkbox inside user control in repeater doesn't fire

I have user control inside a page with single repeater. The problem is when this control is placed inside repeater check box doesn't fire CheckedChanged event. If this would be a dynamically added control I would check whether CheckedCanged event has a handle assigned in Init() but here the event is specified in ascx so I imagine asp.net is responsible for doing all the assignments in right place. I'm lost here :/
By the way. Placing single checkbox inside repeater doesn't fire to. But I can at least use OnItemCommand there
User Control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="QuoteContainer.ascx.cs" Inherits="EhdSite.Controls.QuoteContainer" %>
<asp:TableRow runat="server" ID="trQuoteRow">
<asp:CheckBox runat="server" ID="cbxConfirm" AutoPostBack="true" OnCheckedChanged="CbxConfirmCheckedChanged" />
</asp:TableRow>
Page
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<asp:UpdatePanel runat="server" ID="upQuotes" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater runat="server" ID="rptQuotes">
<ItemTemplate>
<ehd:QuoteContainer
runat="server"
ID="qcQuote"
RowCssClass="rowStyle"
HighlightedRowCssClass="selectedRowStyle"
Quote="<%# Container.DataItem %>"
OnQuoteSelectedChanged="QuoteSelectedChanged" />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
It has to do with the event-chain in ASP.Net, this MSDN page helps to understand it.
The .Net framework resolves the ViewState between the Init- and the Load-event. So if the control is not there after the Init-event, it's ViewState will never be loaded and also it's events will never be fired.
This can get quite tricky at times, especially if one dynamically loaded control should affect the loading of another one...

Resources