SqlMembershipProvider question - asp.net

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

Related

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! :-)

Failed to load viewstate error after moving website to a new server

I don't really know where to start with this one. I am getting:
`Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.`
after moving a website to a new server. The exact same code works on my other server. It happens when I submit one of my forms (but doesn't do it on all form submissions).
Any ideas what can cause this so I have somewhere to look?
Using: ASP.NET 2.
EDIT: I am adding some user controls to a placeholder dynamically at runtime but this same code is working ok on my other server. I have tried clearing the controls in the place holder before adding new ones (as I saw a post about that) but it hasn't helped.
EDIT2: It seems that the postback is just failing. It isn't going into the onClick code of the button either so something is deffintiely screwy .. If I try / catch the exception it seems that all the controls are still added successfully ... Setting my Dynamic UC's to EnableViewState = false resolves this particular error.
EDIT3: Ok, I think I may have a handle on what is happening. For some reason on the old server the form action is default.aspx?action=amend but the new server is showing amend.html?action=amend so I think the re-write module is messing up in IIS. This would explain the control adding issue as well because the action is happening 2 times (I think). I will look into the Rewrite module and see if anything is wrong then post back.
Please, have a look at these articles:
http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html
http://weblogs.asp.net/guys/archive/2004/12/05/275321.aspx
Or try a simple temporary solution - disable viewstate for this placeholder. Either way, I'm puzzled why it actually works on your first server. I'd be glad if someone else will be able to clarify this subject more.
It turns out that the post back Url for the form is wrong on this server (unsure why at the moment, I will update when I know). This is causing the dynamic controls to be added in an unexpected way and causing the error. I noticed this when I managed to post my form and the content didn't update. I manually adjusted the action url using firebug and all is well.
Worth looking at walther's answer regarding dynamic controls and the viewstate though.
Not sure what caused it but I am manually setting the form action in the page load now and it seems to have solved the issue.

User error reporting in ASP.NET

I want to build user friendly error reporting. Wrong input, db connection errors and such.
Problem is i need the same module be implemented for 3 different systems and to use jQuery UI modal boxes for UI.
when i redirect to another page ie.
db connection error i redirect to
error page
when i use return to same page ie.
input value 1 bigger than value 2
when it should be other way around
ASP.NET Ajax UpdatePanel errors,
wrong input for controls within
UpdatePanel that doesn't do regular
postpacks.
thanks for any help with implementation...
To clarify my question
I don't need input or object validation framework. I use ASP.NET and my own business logic to validate on client and server side.
what i really need is
Help with constructing a class that will show errors to users, current process is i catch exception, wrong input value or wrong link and based on that show user friendly message. I have no time and interest in learning logging framework as from my short experience to configure any pre-made high level framework (low level to me is ASP.NET) is harder that to have your own business logic and sometimes requires application re-design...
anyways... My question is pretty clear above. I need way to show centralized messages using jQuery UI.
When i redirect to another page i can save error in Session and get it on other page, if i use return to same page i cannot use Session and had no luck with overriding MasterPage public variables. When i have Ajax UpdatePanel i want again to validate data and show jQuery UI modal...
thats all
A different tactic would be to perform some validation on the client and since you are using jQuery there is a nice form validation plugin called Validation. Here is a good demo page. This will block you post back to the server until you have appropriate data types supplied for you form and will work with your Ajax update panels as well.
With this plugin your HTML mark up is quite straight forward:
<form id="theForm">
<input id="startDate" type="input" class="required datetime"/>
</form>
This will eliminate the need to direct to Error.aspx, store session variables, etc.
For those error that occur on the server, you need to consider whether the user should be able to progress further should a DBConnection error be thrown. In that case you could redirect to your error page, inject your error text and have the client display the content in the jQuery dialog box.
Edit: Are you logging exceptions to a database? If not I would recommend at least a rudimentary log. Other alternatives would be logging to a rolling file appender using log4net. Then, you can load the appropriate error from the logs for display to the user, regardless of how and where you are displaying the error.
See log4net
Also, a not of caution: Don't display DB connection errors to users. Log them so that you know whet is going on and then just tell the user that an error has occurred and that you are aware of it and looking into it.
End Edit
One good way to validate input is to put the validation on your data classes. This allows you to validate them at any time. I know this doesn't solve your redirection scenario which is more of a workflow issue and I hope some others can help you with that.
The reason I mentioned putting input validation on your data classes is that it allows you full control over when your validation is called and it allows you to validate multiple times, on the Client Side and Server Side for example.
A good implementation of this is the FluentValidation framework, which can be extended to automatically generate clientside validation, using the JQuery Validation plugin.
Another option which is becoming popular is Data Annotations. I don't have experience with these yet, but they are worth searching for with your favourite search engine.

EventToCommand / DataContext

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?

How do I get design mode to work for templated user controls?

Is it possible to get design mode to work for templated user controls? I have tried following the How to: Create Templated ASP.NET User Controls on MSDN, and also tried the various tips at the bottom of page for version 2.0 of the framework, but alas, I still get the dreaded "Error creating user control" error, when switching to design view.
Should I just give up, and switch to a custom server control?
There is a Connect bug filed on this as well as several comments on the VS2005 version of the MSDN page. Apparently this is a long-running defect that hasn't been fixed and hasn't got a solution. In ScottGu's post about this feature, he acknowledges this doesn't work (in the comments) and points the commenters to the CompositeControl base class if they want designer support.
Probably not the answer you were hoping for, but it sounds like there's no real solution for the issue except moving to server controls.
I was never able to get it to work either. It can be done easily with a regular server control, though. I posted a quick example as an answer to this question:
ASP.NET: User control with access to the controls that it wraps

Resources