<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>ASP.NET</title>
        <link>http://geekswithblogs.net/plundberg/category/9771.aspx</link>
        <description>ASP.NET</description>
        <language>sv-FI</language>
        <copyright>plundberg</copyright>
        <managingEditor>per.lundberg@ecraft.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>ASP.NET 3.5/AJAX.NET-enabled datepicker snippet using the ASP:Calendar control</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx</link>
            <description>Looking for a &lt;span style="font-weight: bold;"&gt;simple&lt;/span&gt; datepicker that uses AJAX.NET (to avoid full-page postbacks), for your date fields? Look no further! I was on the same "hunt", and ended up writing my own code for it (inspired by other examples/code I was looking at).&lt;br /&gt;
&lt;br /&gt;
The code does all the work using ASP:NET, nothing is done using JavaScript. Below is the code for the solution. This could (and should) be made into a UserControl if you need to use in more than one place&lt;br /&gt;
&lt;br /&gt;
In the .aspx file, put this: (As you see, I am referencing a calendar icon here - use your own icon for this)&lt;br /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                &amp;lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                    &amp;lt;ContentTemplate&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;asp:TextBox ID="requestedDeliveryDateTextBox" runat="server" Width="100" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;asp:ImageButton id="imageButton" runat="server" ImageUrl="~/Images/IconCalendar.png" AlternateText="calendar" &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                            OnClick="ImageButton_Click" CausesValidation="false" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;br /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;div id="calendar" class="calendar" visible="false" runat="server"&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                            &amp;lt;asp:Calendar ID="requestedDeliveryDateCalendar" runat="server" OnSelectionChanged="RequestedDeliveryDateCalendar_SelectionChanged" /&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                        &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                    &amp;lt;/ContentTemplate&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;                &amp;lt;/asp:UpdatePanel&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In the code-behind (aspx.cs file):&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// The calendar icon was clicked.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        protected void ImageButton_Click(object sender, EventArgs eventArgs)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            // Toggle visibility of the calendar.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            calendar.Visible = !calendar.Visible;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// The selected date in the calendar was changed. This method is called via AJAX.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        protected void RequestedDeliveryDateCalendar_SelectionChanged(object sender, EventArgs eventArgs)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        {&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            requestedDeliveryDateTextBox.Text = BOMisc.GetDatePart(requestedDeliveryDateCalendar.SelectedDate);&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;&lt;br /&gt;
            // We hide the calendar here. You can disable this hiding by removing the following line.&lt;br /&gt;
            calendar.Visible = false;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;            // Move the focus to the textbox below the calendar, to make things convenient for the user filling in the form.&lt;br /&gt;
            // Remove this line or change it to reference your own control instead.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;            someTextBox.Focus();&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;        }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And finally, the .css portion. We don't do very much styling of the actual calendar here, we just place it on top of the rest (the z-index part), with a white background to make sure the stuff below doesn't "shine through". We also make the calendar be absolutely positioned so that it becomes a true "dropdown" calendar (it will appear "on top" of everything else on the page).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;.calendar&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;{&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    position: absolute;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    width: 250px;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    padding: 5px;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    background-color: White;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    border: 1px solid #858585;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    z-index: 10;&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
That's it for now, hope this helps. Happy datepicking! :-&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130348"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130348" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/130348.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx</guid>
            <pubDate>Tue, 24 Mar 2009 13:50:02 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/130348.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/03/24/asp.net-3.5ajaxnet-enabled-datepicker-snippet-using-the-aspcalendar-control.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/130348.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Trouble getting TargetInvocationException on your ASP.NET web application?`</title>
            <link>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx</link>
            <description>Sometimes, you get pretty unclear exception messages. The message below is one example of such:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;    Exception type: TargetInvocationException &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    Exception message: Exception has been thrown by the target of an invocation. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;    [...some stuff removed...]&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;    Stack trace:    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp;amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object&amp;amp; instance)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ListView.PerformSelect()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.WebControls.ListView.CreateChildControls()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.EnsureChildControls()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Control.PreRenderRecursiveInternal()&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)&lt;/span&gt;&lt;br /&gt;
 &lt;br /&gt;
I mean, this doesn't tell you anything about where &lt;span style="font-weight: bold;"&gt;in your code&lt;/span&gt; the problem occured. Or does it?&lt;br /&gt;
&lt;br /&gt;
Well, actually, it doesn't. But by experience, you can learn that when working on stuff in an ASP.NET context, this &lt;span style="font-style: italic;"&gt;usually&lt;/span&gt; (in my experience) means that the problem was caused by an ObjectDataSource. It might happen with other controls as well, but this is one case where I have seen it.&lt;br /&gt;
&lt;br /&gt;
The ObjectDataSource "invokes" the method on the class you are telling it to get the data from (or perform the update, etc). The problem with this is that the "real" exception is not shown. My guess is that it would be in the "inner" exception in IIS, and this is not shown here, in the event viewer.&lt;br /&gt;
&lt;br /&gt;
Anyway, when debugging the project inside Visual Studio, I still didn't get any exception information (maybe since I have a custom error handler page set up, that could be removed but it turned out not to be necessary). But, what I did get was this:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New;"&gt;'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ff657321\e4c5c948\App_Web_vtrilm_y.dll', Symbols loaded.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;'WebDev.WebServer.EXE' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\3.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New; background-color: rgb(255, 255, 255); color: rgb(255, 0, 0);"&gt;A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;The thread 0x2bb4 has exited with code 0 (0x0).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The red line at least gives you the &lt;span style="font-style: italic;"&gt;name&lt;/span&gt; of the exception, which in this case was enough to lead me to the real cause of the problem.&lt;br /&gt;
&lt;br /&gt;
Anyway, that's all for now!&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130219"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=130219" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/plundberg/aggbug/130219.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>plundberg</dc:creator>
            <guid>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx</guid>
            <pubDate>Thu, 19 Mar 2009 18:26:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/plundberg/comments/130219.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/plundberg/archive/2009/03/19/trouble-getting-targetinvocationexception-on-your-asp.net-web-application.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/plundberg/comments/commentRss/130219.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>