Unable to retrieve embedded image from compiled ASP.NET assembly - asp.net

I have a simple project with a namespace of 'Search' which contains a number of images which have been marked as embedded resources.
I've entered this into Assembly.vb after checking the reference with Reflector to ensure the image is in the assembly. I've placed the image 'whole.gif' in the root of the application.
<Assembly: System.Web.UI.WebResource("Search.whole.gif", "image/gif")>
My code to render the image is below, it should by rights render the image but doesn't and I can't for the life of me see why.
Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
btnImgAll.ImageUrl = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Search.whole.gif")
End Sub

I found the problem reference to the type which is almost every example given I could find uses Me.GetType(). I chased every other avenue aside from checking this argument until I can across a chance remark in a forum post.
I changed the line
btnImgAll.ImageUrl = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Search.whole.gif")
to
btnImgAll.ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(Content_Modules_RegionSelector), "Search.whole.gif")
where Content_Modules_RegionSelector is the class name of the parent control, which in my case is a simple web user control.

Related

VS 2017 / ASP.net - Global functions not being recognized

I made the jump from VS 2010 (VB) all the way to VS 2017, and that may have been a mistake. I've already been slowed down with bugs, which I have reported. My latest concern is about accessing a global functions class that I have never had a problem with in VS 2010. I have reported it and it is in triage, but I wanted to make sure that something hasn't changed in the versions since 2010, hoping someone here can tell me.
Essentially what happens is that the global class, no matter how it is configured, is not recognized by any other class. Including a reference in a form class causes the IDE to tag it as an error. For example, the code in the GlobalFunctions.vb document:
Public Class GlobalFunctions
Public Function DecodeBase64(strEncoded As String) As String
Dim byt As Byte() = Convert.FromBase64String(strEncoded)
Return (System.Text.ASCIIEncoding.ASCII.GetString(byt))
End Function
Public Function EncodeBase64(strUnencoded As String) As String
Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(strUnencoded)
Return (Convert.ToBase64String(byt))
End Function
End Class
and the calling methods from a form page:
If elemSetting.Attributes("name").Value = "LoginName" Then
Session("MailLoginName") = globalfunctions.DecodeBase64(elemSetting.Attributes("value").Value)
End If
If elemSetting.Attributes("name").Value = "LoginPass" Then
Session("MailLoginPass") = globalfunctions.DecodeBase64(elemSetting.Attributes("value").Value)
End If
Here the errors are being highlighted in the IDE:
And the error messages in the error list:
Understand, too, that I have tried as many variations of declarations as I can think of, such as "Public Shared Function," making the calling sub Shared, defining the global functions document as a Class or a Module, etc. Nothing works.
I've also tried placing the GlobalFunctions.vb class in the project's root directory and in a directory named App_Code, as was suggested in some blog posts around the net.
And since I have had no trouble like this with VS 2010, I assume it's a bug in 2017, which, as I said, I have reported. But I wanted to check with better minds than my own to see if I have overlooked something that may have changed somewhere between 2010 and 2017.
Can someone tell me if I am doing something wrong? Or maybe reaffirm for me that this is, indeed, a bug?
Thanks!
Try to delete and recreate your GlobalFunction.vb as maybe by renaming it in the past it didn't correctly correct everywhere in the project.
I think this is normal. You are using a Class and not a Module so you would need to declare a new instance either call like this:
Dim Globaler As New GlobalFunctions
If elemSetting.Attributes("name").Value = "LoginName" Then
Session("MailLoginName") = Globaler.DecodeBase64(elemSetting.Attributes("value").Value)
End If
If elemSetting.Attributes("name").Value = "LoginPass" Then
Session("MailLoginPass") = Globaler.DecodeBase64(elemSetting.Attributes("value").Value)
End If
Or use a Module and you wont need to declare a new instance.
Also if it still can't be accessed you should check the fact that maybe you just included the file to the solution without including it to the project
To Add new class:
Solution Explorer
Right Click your Project Name (above My Project)
Add
Class

What must I do to let an aspx.vb file see a .vb file in the same project?

I'm getting a compile error "Type 'commonClass' is not defined" in a file directly beneath the project (\\alf.aspx > alf.aspx.vb) on this line of code:
Dim pDAO As New commonClass
There is such a class, in \\App_Code\commonClass.vb:
Public Class commonClass
What is needed for "alf" to see "commonClass"?
This is probably a very basic (no pun intended) question, but I am a newbie to VB.
UPDATE
Does this have anything to do with the code in the legacy project "seeing" the other code, and the new one not: in the legacy project, the Visual Studio menu items are:
FILE
EDIT
VIEW
**WEBSITE**
BUILD
DEBUG
. . .
...whereas in the new project, they are:
FILE
EDIT
VIEW
**PROJECT**
BUILD
DEBUG
. . .
IOW, the new project (which I created using File > New Project > Templates > VB > New Project) has a "PROJECTS" menu item, whereas the legacy project has a "WEBSITE" menu item.
Will re-doing it as File > New Website > ... make the difference? Is there a way to change it to a website without going through that?
UPDATE 2
Both the legacy code, which compiles, and the new project, which doesn't, contain:
// alf.aspx.vb
Partial Class alf
Inherits Page
-and:
// App_Code\commonClass.vb
Public Class commonClass
I see no "Namespace" in either file...
UPDATE 3
So, wondering if the fact that I created a new project rather than a new website is the crux of the problem, I tried creating a new website, but it tells me, "An item with the same key has already been added" and then the WebSite project - which I have not touched beyond creating it - starts off with 21 Errors and 13 Warnings
You have two files. One for your asp.net file (alf.aspx.vb) and one for your commonClass (I assume commonClass.vb). Do both of these files have a Namespace defined and are they both the same Namespace (alf)? If they don't match then you will get the error you are describing.
Namespace alf
Public Class commonClass
Public Shared Sub Execute()
Console.WriteLine("Blah")
End Sub
End Class
End Namespace
I solved this wide-ranging and confounding issue with a three-pronged approach, which is detailed here.

Access 2010 : Queries not working when executed as Sub-Forms

i have created forms which use queries to manipulate and show data, these queries have [criteria] which is taken from a combo box \ text field in the form.
it runs perfectly when i execute the form alone, however when executing it from the MainNavigationForm (tabbed navigation style) it pops-up the "enter criteria" dialog that you usually get when you specify a criteria without any source - like empty brackets [].
i am posting the VB code behind both forms, both behave the same way, and pop the dialog for criteria when launching them from the main navigation form, the first form has more code because it updates the query and values in another combo box based on the value of the first combo box. the second form just runs the query again when value in the combo box is changed.
thank you for your help.
Option Compare Database
Private Sub Command23_Click()
DoCmd.OpenQuery "QryMaintProgPlan", acViewNormal
End Sub
Private Sub id_combo_AfterUpdate()
DoCmd.ShowAllRecords
DoCmd.FindRecord Me!id_combo
Me.maint_combo.Requery
Me.emp_combo.Requery
End Sub
Private Sub maint_combo_AfterUpdate()
Me.emp_combo.Requery
Me.EmployeeID = emp_combo.ItemData(0)
End Sub
2nd form :
Option Compare Database
Private Sub btn_requery_Click()
DoCmd.ShowAllRecords
End Sub
Ok, i have found the answer, i was supposed to use the adress of the navigationSubform in the query criteria because once i launched it from the navigationForm it no longer used the same adress. [Forms]![frmMainNavigation]![NavigationSubform]![id_combo] is the correct one
instead of [Forms]![frmMaintProgPlan]![id_combo].

Change SharePoint site name using a Feature

I am running into a problem when creating a SharePoint 2010 Feature. What I am trying to do is:
Check to see if the site name is the same as the site title.
If it isn't, change the name (and therefore the URL) to match the title.
My code is as follows:
Private Sub ChangeSiteNameToMatchTitle()
_web = SPContext.Current.Web
If _web.Name <> _web.Title Then
_web.Name = _web.Title
_web.Update()
End If
_web.Dispose()
End Sub
This successfully changes the name so that it's identical to the site title, but it causes the Feature to crash at the end of it's activation cycle due to the fact that the site name (and therefore the URL) has changed.
The Feature appears to be trying to reload the ManageFeature.aspx page on the site that activated it, but since the URL has changed it cannot find the page any more.
Does anyone know of a workaround for this, or even if it's possible?
Many thanks!
I would make the Feature hidden and activate it outside of the UI using PowerShell.
Also, per best practice rule SPDisposeCheckID_220, you should not dispose SPContext.Current.Web:
SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.

DevExpress XtraGrid override from CalcRowHeight breaks RepositoryItemImageComboBox

I've recently changed the rowheight for our grid and reduced it a bit (using code from http://www.devexpress.com/Support/Center/KB/p/A859.aspx).
However this breaks our RepositoryItemImageComboBox, the images are no longer shown.
Using a RepositoryItemPictureEdit with an unbound column I can't seem to find how to create a working row filter/row sort.
Who can help me either fix the RepositoryItemImageComboBox images to show again or implement a filtering/sorting RepositoryItemPictureEdit.
This is the column shown with RepositoryItemPictureEdit, No image data on the filterrow is also a problem
This is the column shown with a RepositoryItemImageComboBox.
I've added some code to handle the GridViews CustomDrawCell with no Editor specified. Since we don't really need the editor to choose but show the column read only it suffices.
Private Sub gvw_CustomDrawCell(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles Me.CustomDrawCell
e.Graphics.DrawImage(BitMap, e.Bounds);
end sub

Resources