EventToCommand / DataContext - mvvm-light

I've been using EventToCommand from the MVVM toolkit, but sometimes I the EventToCommand does not seem to be firing on the event that it is mapped to.
I think this has something to do with setting the DataContext? At this point that is simply a guess.
Perhaps a better question would be: I often hit the break point that the EventToCommand syntax refers to, but does not execute when the event occurs. When I subcribe to the event in question in the code behind - I hit a the breakpoint!
Is there any debugging techiques to understand why the imperative code does not get executed, after the command member has be retrieved?
Regards,
Richard

Check the Output window at runtime to see if there are any errors that are being handled and written to output instead of throwing a runtime exception.
Also, you can try bringing the Galasoft.MvvmLight.Extras project into your solution, and changing your reference to point to it. That will let you debug through the code to see if something is failing there. If you do this, I would suggest putting a breakpoint in the OnAttached() method.
Is this an intermittent issue? What does the XAML look like?

Related

RaisePostDataChangedEvent called on callbacks too?

I'm debugging some weird behavior in a ASP.NET webforms app. I've narrowed it down to something I find peculiar: A control which implements IPostBackDataHandler has it's RaisePostDataChangedEvent called even if it's a callback from another control. I've reproduced this in a dummy test page.
Information on how it SHOULD be is scarce. I've found only one page which seems to imply that it's only called on postbacks, and not on callbacks.
Is this how it should be? Has it always been so?
After some more digging around in ASP.NET source code I think I can say with certainty - that's how it's always been.
Awesome. I shudder to think how many places in the application have subtle flaws because of this. It's a good thing we're on the path of replacing it all with MVC.

Methods for asp:FileUpload object?

. .
I'm trying to set up an <asp:FileUpload> object to fire on the client side after I click "Browse" and select a file. (Specifically, I want it to return the name of the file that was selected.)
However, I'm having a hard time trying to find the correct method. None of the server-side methods do what I want (and I'd prefer it to fire on the client-side, anyway), and none of the various combinations of client-side methods (onclick, onchange, etc.) seem to work.
Ideas, anyone?
Thanks!
Edit: I think I may have answered my own question. I ended up abandoning the ASP.NET <asp:FileUpload> tool, and simply used the lower-tech <input type="file"> instead. Methods seem to work just fine with that.
Edit #2: Nothing doing. That works fine on the client side, but then I have the problem of trying to save the file on the server side. I guess it's back to Square 1.
Edit #3: I think this is the final answer. I changed it back to <asp:FileUpload ID="FileUploader"> and added a FileUploader.Attributes.Add to the Page_Load. It sees that and fires with no problem. Of course, now I'm getting an "Object expected" error (because the script it's calling comes after the code -- ah, the joys of dealing with JavaScript order).
As I mentioned in my edit yesterday -- the answer ended up being to add the attributes in the Page_Load. Let's say my FileUpload ID is "FileUploader". I added FileUploader.Attributes.Add("onchange","CallThisCode();"). That did the trick!
Now I just need to figure out how to make it call the JavaScript correctly -- a different issue altogether! :-)

Avoid try/catch hell in my Telerik controls

I posted for some help over here:
Avoiding try/catch hell in my web pages
I have added an 'override OnError' in a common base class from all my pages, and can confirm that it works properly by putting a breakpoint within the function. However, I still get an exception propagating to the client, no matter what I do. Here is my issue:
1) I have a Telerik Grid control that is updated based on the value of a ComboBox. If an exception occurs and I catch it in a try/catch block then everything is fine.
2) If I get an exception when the ComboBox is changed but there is NO use of a try/catch block, then the error is caught in OnError. However, now I get a PageRequestManagerServerErrorException error just popping up in the client Ajax response (Javacript).
Any help?
There could be many reasons why it's happening. For one, it could be something with client-side rendering that's causing it, or it could be an AJAX request from an update panel or the RadAjaxPanel... one way to possibly tell is to tap into the Sys.WebForms.PageRequestManager's endRequest event, which is discussed briefly here: http://encosia.com/2007/07/18/how-to-improve-aspnet-ajax-error-handling/
So the error is possibly not happening around that area of code that has the try/catch block, but could be caused from something internal in the Telerik processes...
Could you share any code/markup?
Thanks.

SqlMembershipProvider question

When you create the Register Control for the SqlMembersipProvider nothing happens if they register and the username or email is in use. Is there a tutorial or override function that fixes this in asp.net 2.0
You most certainly should see a red error message indicating that the operation failed and why.
If you do not see this then there is something hinky with the way you have built your create-user page.
Try simply dragging a CreateUserWizard onto a new WebForm and try what you describe.
And nick is correct in saying that you really should acknowledge the time and effort people take to help you with your problems by taking 2 seconds and clicking upvote and/or accept.
That is the way that stackoverflow works and if you don't get with the program you are going to be ignored.
You may need to register an event handler for the LoginError event.
See this article for lots of details: https://web.archive.org/web/20210513220018/http://aspnet.4guysfromrolla.com/articles/120705-1.aspx

What is the best way the _DoPostBack javascript method in Asp.net

I want to set a breakpoint on the __DoPostBack method, but it's a pain to find the correct file to set the breakpoint in.
The method __DoPostBack is contained in an auto-generated js file called something like:
ScriptResource.axd?d=P_lo2...
After a few post-backs visual studio gets littered with many of these files, and it's a bit of a bear to check which one the current page is referencing. Any thoughts?
If you using IE7 for testing you can use View -> Script Debugger -> Break on next statement and then just click the button that generates the event(__DoPostBack)
TBH, I dont think there is much value in setting a breakpoint within the Javascript since it pretty much comes straight back to the server anyways.
It would be best to set breakpoints in your server code.. Depending on what you are trying to debug this will be in different places.. Either in the page event cycle or a controls IPostBackEventHandler.RaisePostBackEvent handler.

Resources