I have a same issue with you. Finally I found a way to fixed it. Maybe you can try disable link's viewstat as follows:
link.EnableViewState = false
Question
I have two stylesheets in my App_Themes/Default/ folder: BaseStylesheet.css and NonConvert.css
Here is the code that I have on my example webform. I add the LastModifiedDate to the end of each of my CSS files in my App_Themes folder. When they are updated, the LastModifiedDate automatically updates.
Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
'CACHING - Add a LastModifiedDate to all CSS files in the App_Themes directory
Dim link As HtmlLink = Nothing
For Each c As Control In Header.Controls
If TypeOf c Is HtmlLink Then
link = TryCast(c, HtmlLink)
If link.Href.IndexOf("App_Themes/", StringComparison.InvariantCultureIgnoreCase) >= 0 AndAlso link.Href.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase) Then
link.Href += String.Format("?t={0}", GetLastModifiedDateString(link.Href))
End If
End If
Next
End Sub
Public Shared Function GetLastModifiedDateString(ByVal filePath As String) As String
Dim fileInfo As New IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(filePath))
If fileInfo.Exists Then
Return String.Format("{0:yyyyMMddHHmmss}", fileInfo.LastWriteTimeUtc)
End If
Return String.Empty
End Function
These two methods are working just fine. The html output looks like this:
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
<link href="../../App_Themes/Default/NonConvert.css?t=20140228175530" type="text/css" rel="stylesheet" />
When I add a button and do a postback, this is my html output:
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
What am I missing? Do I have to remove the querystrings before the viewstate saves?
No correct solution
OTHER TIPS
I have a same issue with you. Finally I found a way to fixed it. Maybe you can try disable link's viewstat as follows:
link.EnableViewState = false