Button in UpdatePanel not firing Click event: RequiredFieldValidator the cause - asp.net

I'm working on a page that consists of Telerik RadToolTip, an UpdatePanel that contains a Button, and a few user controls. There is also a Master Page, which is where the ScriptManager is located.
Previously, I had a RadAjaxManager on the Master Page and RadAjaxProxyManager. I removed them and began to implement standard Update Panels because of complexities within the User Controls.
Now, however, I can't seem to get any of this page to behave as expected. When I place a Button in the UpdatePanel, I expect a Partial Postback and I expect the Button's OnClick event to be fired. However, when I run this code with a breakpoint in the btnPostBack_Click event code, the breakpoint never gets hit.
If I cut and paste the same controls with the same settings into a new project, the breakpoint gets hit. Is there something in the environment of the site or could Telerik be interfering with the Button's Click event? I've removed all RadAjaxManager/Proxies.
<%# Page Title="" Language="C#" MasterPageFile="~/AV.Master" AutoEventWireup="true"
CodeBehind="AssetView.aspx.cs" Inherits="AV_ASP_UI.AssetPages.AssetView" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%# Register TagPrefix="uc" TagName="AssetDiagram" Src="~/Controls/AssetDiagram.ascx" %>
<%# Register TagPrefix="uc" TagName="AssetInfo" Src="~/Controls/AssetInfo.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
function DoPartialPostBack(command, id) {
document.getElementById("<%= hfldId.ClientID %>").value = id;
document.getElementById("<%= btnPostBack.ClientID %>").click();
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:HiddenField ID="hfldId" runat="server" />
<telerik:RadToolTip ID="RadToolTip1" runat="server" Modal="true" ShowEvent="FromCode"
Position="Center" RelativeTo="BrowserWindow" HideEvent="FromCode" TargetControlID="hfldFireToolTip">
</telerik:RadToolTip>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Button ID="btnPostBack" runat="server" Text="Button" style="visibility: hidden" OnClick="btnPostBack_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlWorkArea" CssClass="pnlWorkArea" runat="server" Height="770px" onMouseDown="hideSVGTtip(event);">
<uc:AssetDiagram ID="ucAssetDiagram" runat="server" CanvasHeight="720" CanvasWidth="276" />
<uc:AssetInfo ID="ucAssetInfo" runat="server"/>
</asp:Panel>
</asp:Content>

Related

UpdatePanel not working in default document

My simple application has one page Default.aspx.
If I hit the page at /app/default the page loads and everything works. If i go to /app/ with no file name the page loads but my button does not work.
looking in fiddler I can see a working request starts like
1|#||4|219|updatePanel|MainContent_upDemo|
but a bad request returns the page starting with and the updatepanel javascript can't parse it.
Turning off friendly URLs has the same issue but I now have to go to /app/Default.aspx
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CasualFrontEnd._Default" EnableEventValidation="true" %>
<%# Register TagPrefix="cc1" Namespace="EAV" Assembly="EAV" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="upCasual" runat="server">
<ContentTemplate>
<asp:Label ID="lblTesting" runat="server" Text="Label"></asp:Label>
<asp:Button ID="BtnApply" CausesValidation="true" runat="server" Text="Apply" OnClick="BtnApply_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
It looks like a bug in the way the default path is handled with no route.
my solution:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("nofile", "", "~/Default.aspx");
//var settings = new FriendlyUrlSettings();
//settings.AutoRedirectMode = RedirectMode.Temporary;
//routes.EnableFriendlyUrls(settings);
}

Textbox Date Rendering Truncate Leading 0 part - ajaxToolkit CalendarExtender

I have a textbox in a aspx page. The value for the textbox is set in code-behind. When I put a break-point the text value set is “06/03/2013”. But it renders as 6/3/2013 inside the textbox.
txtDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
//06/03/2013
How can I make it to render as 06/03/2013?
UPDATE
Note: Even if I use CultureInfo.InvariantCulture, this issue is not resolved.
Note: I found that the issue goes off if I remove the ajax calendar control. Is there a way to work it correct with ajax control?
ASP.NET Page
<%# Page Title="Recovery" Language="C#" MasterPageFile="~/SimplifiedMaster.Master"
AutoEventWireup="true" CodeBehind="Recovery.aspx.cs" Inherits="MyCompany.ServicesSupportSite.UI.Recovery" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="headContent" ContentPlaceHolderID="headContentPlaceholder" runat="server">
</asp:Content>
<asp:Content ID="detailContent" ContentPlaceHolderID="detailContentPlaceholder" runat="server">
<asp:ScriptManager ID="scrRecovery" runat="server" />
<div class="recoveryValueDiv">
<asp:TextBox ID="txtDate" runat="server" CssClass="recoveryDate" Width="100px" MaxLength="10"
TabIndex="2"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate"
CssClass="calendarStyle" />
</div>
</asp:Content>
<asp:Content ID="scriptContent" ContentPlaceHolderID="bottomScriptContentPlaceholder"
runat="server">
</asp:Content>
Use InvariantCulture to avoid culture issues and force / as separator:
txtDate.Text = DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
Demo
Note that / has a special meaning: replace me with the current culture's date separator.
Using the InvariantCulture Property
Set the Format property of CalendarExtender:
<ajaxToolkit:CalendarExtender Format="MM/dd/yyyy"
ID="CalendarExtender1" runat="server"
TargetControlID="txtDate"
CssClass="calendarStyle" />
REFERENCES:
Calendar Extender Date Format
ASP.NET AJAX Calendar Extender – Tips and Tricks

Asp.net web forms control in asp.net mvc

I'm trying to inject an asp.net classic web control to my asp.net mvc application. This control doesn't use view state or post back so it works fine.
But I can't plug a real-time provided value in its attribute. This code
<my:Control runat="server" Tag="<%: Model.ID %>" />
ends up with the tag value just set explicitly to "<%: Model.ID %>".
Is there a way to make it work?
I believe the syntax is as follows:
<my:Control runat="server" Tag="<%# Model.ID %>" />
The other gotcha is you must call .DataBind() on the Control at some point after the Control has been initialized. This probably means taping into the Page_Load or OnInit events of the Page.
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<script runat="server">
protected override void OnInit(EventArgs e)
{
this.Label1.DataBind();
base.OnInit(e);
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<asp:Label ID="Label1" runat="server" Text="<%# DateTime.Now %>" />
</asp:Content>
Or, if you have access to the source, you could add a call to .DataBind() somewhere before the final Render. You would have to experiment with that.
Hope this helps.
Well, seems like the only way to do this is injecting code the control renders to the page directly. In my case the control renders a silverlight object with some javascript so I put it at the page as is.

Remembering active tab on refresh of ASPX page

I've got an ASPX page set up that loads and displays dynamic data from a local SQLite database. Since the data is being written to the database from a separate C# application, I've set up my ASPX page to refresh every 30 seconds when the database has flagged itself as actively receiving new data.
On my ASPX page, I've got a TabContainer with several different TabPanels that each represent a different view of the data. Now, when my page is being refreshed, the active tab panel is being reset to the one set in my ASPX page as the ActiveTabIndex.
I was wondering if there is an easy way to persist which tab is being remembered.
Thanks!
Edited to add code sample
MyPage.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPageFile.master" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" Runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager" runat="server" />
<asp:TabContainer ID="tabContainer" runat="server" ActiveTabIndex="1" CssClass="myTabStyle" Visible="true">
<asp:TabPanel ID="tab1" runat="server" HeaderText="Tab 1">
<ContentTemplate>
<p>Hello</p>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="tab2" runat="server" HeaderText="Tab 2">
<ContentTemplate>
<asp:PlaceHolder ID="tab2placeholder" runat="server" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="tab3" runat="server" HeaderText="Tab 3">
<ContentTemplate>
<asp:TabContainer ID="tab3content" runat="server" ActiveTabIndex="0" CssClass="myTabeStyle" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="tab4" runat="server" HeaderText="Tab 4">
<ContentTemplate>
<p>Blah.</p>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</asp:Content>
MyPage.aspx.cs
public partial class MyPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
...
if (isInProgress)
{
Response.AddHeader("Refresh", "30");
}
LoadTab1();
LoadTab2();
LoadTab3();
LoadTab4();
...
}
}
Try putting UpdatePanels within in the TabPanels. If you post a code sample of your ASPX it would be easier to help.
If you are doing full postbacks all the time then save it in your ASP.NET session. e.g.
Session["ActiveTab"] = index;
Then to retrieve it:
int? activeTab = Session["ActiveTab"] as int?;
Otherwise using jQuery ajax to refresh the data, is in my experience a much better way to go than using UpdatePanels. But it looks like you are already committed to MS Ajax so go with Mike's recommendation to use an ajax timer instead of a refresh header.

Hidden panel doesn't center correctly when displayed

I've got a simple AlwaysVisibleControlExtender that extends a small Panel containing a "Loading..." message and animated GIF. The whole thing is inside an UpdateProgress control, so it only displays when my app is processing. I've got it set to display at the top center. It works fine, but I've noticed that it displays slightly to the right of where it should be. If I resize the window slightly, the panel snaps to the correct position.
My guess is that it's calculating where the center is before the UpdateProgress control allows the Panel to be rendered, thus the Panel has a width of zero. Only after the Panel is displayed does it correctly calculate the center. Is there a workaround for this?
Update: Here's the markup:
<%# Page Language="VB" MasterPageFile="~/Compass.master" AutoEventWireup="false" CodeFile="SubmissionPrep.aspx.vb" Inherits="SubmissionPrep" Title="Untitled Page" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<%-- Data and Controls here --%>
<asp:UpdateProgress ID="ProcessingUpdateProgress" runat="server">
<ProgressTemplate>
<asp:Panel ID="ProcessingPanel" runat="server" CssClass="loading">
Processing...
<img src="images/ajax-loader.gif" alt="" />
</asp:Panel>
<ajax:AlwaysVisibleControlExtender ID="ProcessingAlwaysVisibleControlExtender" runat="server"
TargetControlID="ProcessingPanel" VerticalSide="Top" HorizontalSide="Center">
</ajax:AlwaysVisibleControlExtender>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
I have implemented Progressbar with the help of this article, so I have not get any issue
this is great article..... and explaining setp by step, plz check
http://www.codedigest.com/Articles/ASPNETAJAX/125_Using_UpdateProgress_Control_Effectively.aspx

Resources