Archive for the '.Net' Category

Download vsto through clickonce install

I was getting this error while trying to deploy an excel-add-in through clickonce.

URLDownloadToCacheFile failed with HRESULT ‘-2146697210’

Error: An error occurred trying to download ‘http://###/ExcelAddIn.vsto’.

Simple fix – add .vsto –> application/x-ms-vsto to the MIME type in IIS.

Label not displaying ampersand

Kind of a weird one – Ampersands disappear in labels, unless you set the UseMnemonic property to false.

VB vs C#

As a 15+ year VB coder, I found this podcast to be pretty enlightening about the future of VB along with some myth busting.

Does VB have a future

Install IE6 on Vista/Windows 7

If you need to test sites for IE 6 compatibility, it is hard to beat Virtual PC. These images expire after a while, but MS has been posting updates.

IE 6 image

Center datagrid pager style in IE8


<PagerStyle HorizontalAlign="Center" />

stopped working in IE8. Updated the css to the following and everything centered fine.


.dgrGridpager table
{
margin: 0 auto 2px auto;
}

Hide horizontal scrollbar in tablelayoutpanel

When populating a tablelayoutpanel dynamically, the horizontal scrollbar kept appearing, even though there was no need for it.

It looks like there is no property to disable only the horizontal scrollbar, but I did find this workaround.

Pad the layoutpanel to the width of the horizontal scroll bar and the scroll bar will disappear.


int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;

tableLayoutPanel1.Padding = new Padding(0, 0, vertScrollWidth, 0);

MySql with .Net SqlDataSource on hosted server

I was getting an error saying the .Net provider could not be found when attempting to connect to a MySql db in hosted environment. If the MySql.Data.MySqlClient is not loaded in the GAC on the hosted server, you will need to add a reference in your web.config, if you want to use the SqlDataSource control.

  1.  
  2. web.config - make sure the version matches your MySqlClient version
  3.  
  4. <system.data>
  5. <DbProviderFactories>
  6. <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.2.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  7. </DbProviderFactories>
  8. </system.data>
  9.  
  10. SqlDataSource reference
  11.  
  12. <asp:SqlDataSource ProviderName="MySql.Data.MySqlClient" ID="dsData" runat="server" ></asp:SqlDataSource>
  13.  

Reference ClickOnce publish version

If you are trying to keep your About window in sync with the published version in ClickOnce, rather than the assembly version, you can reference My.Application.Deployment.CurrentVersion. However, this only works on the installed application, not in Visual Studio.


If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then
Me.LabelVersion.Text = String.Format("Version {0}", My.Application.Deployment.CurrentVersion)
Else
Me.LabelVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString)
End If

IE8 and HTTP 403.9 – Access Forbidden: Too many users are connected

I upgraded to IE8 and started getting 403.9 on my local machine during testing on XP with IIS 5.1.

Turns out, you now have to disable HTTP Keep-Alives in the IIS Admin properties for the local site.

Here is more info: Disable Keep-Alive

Check for null date value

I have a class with a property of type date. Since this is a value type, it can’t be set to null.

If the date value is not set, it is initialized with the smallest date possible: #12:00:00 AM#, which will always return false if you use isNothing.

Instead, compare the date to DateTime.MinValue


If clsDate.dateEquals = DateTime.MinValue Then

force __doPostBack generation

Sometimes you want the __doPostBack function to be forced on a aspx page.

Add this line in your Page_Load event:

Page.ClientScript.GetPostBackClientHyperlink(New Control(), String.Empty)

onMouseOut for nested DIV

This was making me crazy for a bit. The onMouseOut event fires for the parent DIV when moving over the child DIV elements.

I had several custom menus nested in divs and I only wanted to hide the entire parent DIV block when the mouse left the parent.

Came across the handy script below which works like a charm.

js for mouse out

Fixed header for repeater control

Here is a simple solution to get an excel like fixed header at the top of a repeater control.

Fixed headers

e.item.DataItem causes invalid cast exception

I kept getting an exception when attempting to cast e.Item.DataItem to DataRowView in a repeater control ItemDataBound event.

Issue was I was binding a DataReader, which requires DBDataRecord in System.Data.Common. Dataset uses DataRowView.

Microsoft KB

If the data source is a DataReader object, you must cast e.Item.DataItem as type DBDataRecord (from System.Data.Common) in the event handler. If the data source is a DataTable, you must cast e.Item.DataItem as type DataRowView.

“Page cannot be found” when browsing aspx in IIS 6

In Windows 2003, all webservice extensions are “Prohibited” by default.

You need to enable ASP .net extensions to resolve the issue:

1. Open up IIS manager or, from your Run command, type inetmgr and press enter.
2. Expand the appropriate nodes in the IIS to locate the “Webservice Extensions” Node
3. Click on the same.
4. You will find a list of “prohibited” extensions in the right.
5. Click on ASP.NET and “allow” it

IE6 does not support position:fixed

There are some script workarounds that might resolve IE6 not rendering position:fixed, but I just changed to position:absolute.

Disable Javascript in IE7

The only time I could see needing to do this is when you are testing if users have js enabled.

To disable Javascript in IE7

1. Tools / Internet Options / Security

2. Click Custom Level

3. In the Scripting section – click Disable for Active Scripting.

4. Close and restart your browser.

How to export Excel from AJAX in .Net

In order to use the standard response.write method of exporting to excel, you need to force AJAX to make a full postback. Otherwise, parsing errors occur.

To force a postback, assign a control to a trigger and put the export logic in the control click event or in the page.ispostback portion of page_load.

Trigger syntax:


</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnGo" />
</Triggers>
</asp:UpdatePanel>

Authenticated users getting logged out randomly

I was having a problem on a shared server with authenticated users getting logged out every couple of minutes. Turned out to be a simple fix by configuring a static machinekey for the web.config. By default, the authentication key is autogenerated by IIS each time the asp .net process cycles, which can be often on a shared machine.

MS info on MachineKey

IE6 AJAX problem

I put together a fairly simple chunk of code to display a loading image while a chart was rendering. This used an updatepanel and timer. It ran fine with IE6/7 locally and IE7 remote. But IE6 would not display the image on the remote server. Just a blank page and then the chart.

I looked at a lot of different posts and finally came to the solution. It looks like AJAX will automatically compress output. IE7 can handle this, but IE6 can not. By disabling the default compression, the image now appears in IE6 on the remote server.


<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true"/>
</scripting>
</system.web.extensions>


A similar type of issue.

  1.  

Next Page »