ASP.NET WebForms application. There is a custom web control (IE inherits from System.Web.UI.WebControls.WebControl). I can put breakpoints anywhere in CreateChildControls() or any other overloaded method and these breakpoints work fine. However, if I try to add a breakpoint to a method that is bound to a Button on the page, I get an error on the breakpoint:
The breakpoint will not currently be hit. No executable code of the debugger's target code is associated with this line. Possible causes include: conditional compilation, compiler optimizations, or the target architecture of this line is not supported by the current debugger code type.
I've tried cleaning the solution, deleting all bin/obj folders, restarting local IIS, recycling the app pool, all to no avail.
Code is in VB.NET (sorry).
Here is the function definition (in the WebControl code):
Private Sub AddToCartClick(ByVal sender As Object, ByVal e As System.EventArgs)
// breakpoint on line 1
Here is the code that ties the function to the Button:
Dim button = new Button
AddHandler button.Click, AddressOf AddToCartClick
The code executes and has worked for a long time, but I cannot debug it with breakpoints.
Related
I'm desperate. I have a website, didn't make any changes to it. VS2019 notified about the available update and I ran it. Then, when I opened my website, I have 99 errors regarding WithEvents.
All controls in .vb files underlined red, can't debug, and any changes I make (like adding a new control) won't reflect in run time.
I have .design files and all controls are in it declared correctly (WithEvents).
.vb
lblID.Text = i.student_id.ToString
.design
Protected WithEvents lblID As Global.System.Web.UI.WebControls.Label
I tried to remove/add controls.
I tried to create a new website, new .asp/.vb pages. Copying the code from the old ones gave me the same errors.
I tried to use OpenFileDialog() control inside my Webform Application but it's not working.
I tried this coding but it gave me error :
System.Windows.Forms.OpenFileDialog Not defined
Private Sub FnOpenFileDialog()
Dim openfile As New System.Windows.Forms.OpenFileDialog
openfile.Filter = String.Format("Image file (*.jpg)|*.jpg")
openfile.Multiselect = True
openfile.ShowDialog()
End Sub
Private Sub btnUpload_PreRender(sender As Object, e As EventArgs) Handles btnUpload.PreRender
Dim objThread As New Thread(AddressOf FnOpenFileDialog)
objThread.IsBackground = True
objThread.SetApartmentState(ApartmentState.STA)
objThread.Start()
End Sub
Or is there any way on how to do it? I don't want to use FileUpload control because it shows textbox + button. I only want to show the Button() control.
I refer to this website How to Apply OpenFileDialog Function to a WebApplication
In a ASP.NET web application, the VB code is run on the web server. So even if you would succeed in using OpenFileDialog that would result in the dialog being showed on the server, not in the browser.
JavaScript won't help you either, as the browswer sandbox in which JavaScripts run doesn't allow access to the file system (which is good from a security perspective). You simply have to accept that you need to work with the file upload control. You might be able to customize the appearance a bit by applying styles through css.
Use HTML input file ,as follow:
<input id="File1" type="file" />
I am trying to debug some code in my code behind files for as aspx page. I have debug set to true both in the page and in my web.config.
Can someone tell me why a) the breakpoint never fires even though the dropdown gets filled and b) why when i uncomment the msgbox it never fires and the dropdown does NOT fill.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack Then
ddlCity.Items.Clear()
Dim context As New enerteckEntities()
'Dim query = context.DistinctCityFromZiptax(Convert.ToInt16(ddlState.SelectedValue))
Dim query = From c In context.ziptaxes Where c.StateID = ddlState.SelectedValue Order By c.City Select c.City, c.ZipTaxId
'MsgBox(query.Distinct().ToList())
ddlCity.DataSource = query.Distinct().ToList()
ddlCity.DataValueField = "ziptaxid"
ddlCity.DataTextField = "City"
ddlCity.DataBind()
End If
End Sub
Well based on your code, you will only execute this after a PostBack and not on initial Page Load.
MsgBox will never show up because this is not a WinForms application! You cannot use that in a web.application. If you want you can use Response.Write() or just add a dummy Label to your page and set the text property temporarily. It is the same effect.
The easiest would be to just debug it. Make sure your breakpoints are full Red dots, and you must be in Debug mode. If you are trying to debug from IIS then you must attach to process. If you are using IIS7 (I am assuming you are) then you must go to:
Debug Menu > Attach to Process > Find the process named "w3wp.exe" and double click on it.
You are now attached.
If your breakpoints are not full red dots after starting debug, then your compiled code and your debug files do not match. Do a Rebuild as opposed to a Build. Beyond that you might be having a funky problem, you can try deleting your obj and bin folders (make sure to save any third party dlls first).
To hit a break point visual studio has to attach to the process hosting the aspx page.
This is typically done in a Web Application Project by pressing the F5 key or clicking on the "Debug" menu and clicking "Start Debugging".
I am using asp.net 4, .net 4 and masterpages. I added in the following code to my child page
Private Sub FoodChain_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
MyBase.OnInit(e)
PopulateDropdowns()
HideQuestionDiv()
HideDropdowns()
End Sub
and ran my app. The app runs fine but when I went back to the design view I now get an error saying "object reference not set to an instance". This is only during design time view and referencing the main place holder.
Is this a bug or am I missing something ? As I said the application runs fine and there are now issues during runtime.
Try putting all your databinding inside the following. (sorry about the c# code). I think it is Me.DesignMode in VB.
if (!this.DesignMode)
{
PopulateDropdowns();
HideQuestionDiv();
HideDropdowns();
}
I'm not sure if this works correctly for nested user controls but worth a try. Note that this won't work inside a constructor, only other events.
MSDN here.
My module's Page_Load event is firing twice for each "actual" load. On the initial load both loads' Page.IsPostBack property is false.
I've renamed Page_Load to Module_Load to verify the name wasn't an issue. I've made sure the method isn't handling both Me.Load and MyBase.Load, which has been the case in the past.
The only thing I'm doing out of the ordinary is that my module is inheriting from an intermediate base class. Could this be the culprit?
My module:
Namespace Modules.RedactedNamespace
Public Class List
Inherits RedactedModuleBase
Protected Sub Module_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.Page.IsPostBack Then
BindList()
End If
End Sub
End Class
End Namespace
My base:
Namespace Modules.RedactedNamespace
Public MustInherit Class RedactedModuleBase
Inherits DotNetNuke.Entities.Modules.PortalModuleBase
End Class
End Namespace
Edit (This fixed it) - I had an Image without an ImageUrl. Presumably this is set by my CollapsiblePanelExtender but rendered with a blank src.
This can happen if you have an img tag with an empty src attribute.
I know this sounds strange, but I believe it has to do with the web browser trying to figure out how to load the image with a blank SRC.
I don't know the protocols involved, but I'd bet there is some ambiguity regarding how to resolve empty string.
So, in the case of some browsers, it actually fires a web request to the current URL hoping the image comes back.
Sounds like a reasonable assumption, but it just so happens to break many ASP.Net web forms.