p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4.5 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=710)
-   -   Ch 11 jQuery unobtrusive javascript stopped the ShowMessageBox (http://p2p.wrox.com/showthread.php?t=92066)

AlanWheeler January 28th, 2014 04:06 PM

Ch 11 jQuery unobtrusive javascript stopped the ShowMessageBox
Hi Imar,

When the ContactForm validation is changed over to Unobstrusive JavaScript the ShowMessageBox disappeared.

Is that because jQuery doesn't translate that part of the validation object that was previously being used, or is there something else to be done to get that back?


Best Regards,

Imar January 28th, 2014 04:21 PM

Maybe you turned that off? When I turn on ShowMessageBox="True" on the summary, it works fine for me.



AlanWheeler January 28th, 2014 05:36 PM

The markup page for the ContactForm.ascx (the user control) has the attribute ' ShowMessageBox="True" '.

The version of jquery is 2.1.0. It would take me some time to go through and revert to the version in the book, but I can do that later.

I went back and changed the lines in Web.config and Frontend.Master to read the way they were before setting up for jQuery. I had to comment out the jQuery script in the ContactForm.ascx as well since the references were no longer there. When I run the page that way, the message box shows up. When I revert again to having jQuery running, the message box is gone.

But it sounds like you are telling me the message box should be there even with jQuery, so at present this is a mystery unless the newer version of jquery is different in that way to the version from the book. That seems unlikely.

Of course the other possibility is that I've done something incorrect; but when I revert back and forth all I'm changing is which client side code is being created/sent, yes? I'm not changing anything else. Since the message box shows up when I revert that must mean something.

Best Regards,

EricCulbertson January 29th, 2014 05:30 AM

surely, your coding is playing up with you why you are not getting the right outcome

AlanWheeler January 29th, 2014 10:17 AM

Hi Imar,

Does it work to copy any of the chapters in the downloaded code and simply open them in Visual Studio as a new website solution?

For ex: C:\BegASPNET\Source\Chapter 12 -> C:\BegASPNET\Site2. And then just run that as the website I'm working on?

I briefly tried to do that this morning. I did not get the ShowMessageBox (I did turn it on in the ContactForm.ascx properties grid for the ValidationSummary1 and it showed up TRUE in the markup).

I commented out the mySmtpClient.Send(myMessage) since that's not critical to see the jQuery animation; I put a 5 second sleep there. When I click send w/ validated data, the animation runs, so jQuery is functioning. I also checked the transmitted html and found the 1.7.2 jquery src attribute.

I just don't have the ShowMessageBox, even using the downloaded code.

So that begs the question what could possibly be at play?

Best Regards,

Imar February 17th, 2014 06:40 PM

Hi Alan,

Sorry for my late reply. I wanted to dig into this before replying, but I never found the time to do so.

I think you found an issue in the code. Using unobtrusive validation requires an additional library and some code. I remember that the behavior changed somewhat between the release candidate and RTM version of VS 2012 and it looks like I missed a step when reviewing the final manuscript. The issue went unnoticed because the ContactForm is wrapped in an UpdatePanel, hiding the fact that the user control does NOT validate at the client anymore, but only at the server (after which the results in the ValidationSummary are sent to the browser as HTML). By enabling the ShowMessageBox option this became apparent, as that option works only at the client, before the postback. Since the form didn't do client side validation, the message box never showed up.

Fortunately, the fix is easy. Here's what I have in my upcoming 4.5.1 book which should resolve the issue:

1. In order to use unobtrusive validation together with jQuery, you need to install the package Microsoft.AspNet.ScriptManager.WebForms. To do this, open the Package Manager Console, enter the following command and hit enter:

Install-Package Microsoft.AspNet.ScriptManager.WebForms
2. After a short delay you should get a confirmation that the package has been installed. In addition, you should see a number of files appear in the WebForms folder located under the Scripts folder.

3. Open up the master page and change the reference to the jQuery library so it points to the ScriptResourceDefinition you created in the Global.asax file and insert a reference to the file WebUIValidation.js which handles the client side validation.

<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Path="~/Scripts/WebForms/WebUIValidation.js" />

If you didn’t make this change, jQuery would be included twice on pages that use the validation controls; once from the code in Global.asax, and once from the reference in the ScriptManager control. By having the ScriptReference point to the ScriptResourceDefinition defined in
Global.asax, ASP.NET sees that it’s pointing to the same JavaScript library and includes the reference only once.

If I am not mistaken, the change to the jQuery library is also in the 4.5 book, so I don't think you need that step.

After that, the control should validate at the client, and ShowMessageBox should work as advertised.

Hope this helps (and works!).


AlanWheeler March 3rd, 2014 03:27 PM

Reporting back
Hi Imar,

I was finally able to spend some time on this.

Bottom line: Adding the .js file you mentioned put the message box back into the web site.

I have a several questions:

1. My understanding of your post: Were you saying that without WebUIValidation.js, NO client side validation was being performed to include even the client side checks for text, email, etc? Or was it just the Message Box that wasn't being done at the client side?

2. On a separate note: While I was working on the code, to make the email debugging easier, I had added default data for the contact us form so I could simply click Send without having to type data in, and then I added a Clear Message button to reset the text boxes to the null string in case I wanted to type data in; it seemed to work fine. But after using that control, when I was running the test of the Show Message Box, during validation and odd thing happened. I received 2 Message Boxes one after the other. If instead I manually deleted the text boxes, then I receive only one Show Message box during validation. Is that enough information for you to comment why the Show Message box was displayed twice in a row after I created a button click method to clear the email?


Best Regards,

Imar March 5th, 2014 06:49 AM

Hi Alan,

1) It wasn't doing any client side validation at all.

2) I am not sure I understand what the problem / situation is. Maybe .NET fired its own validation as well. Can you provide more detailed steps with code or better yet an online demo page showing the behavior?


AlanWheeler March 5th, 2014 03:48 PM

Hi Imar,

This link will take you to site that I created using your tutorial in the book. http://wrox.wbctech.net/Default.aspx

If you go to the Contact Us page do the following:

Click Clear Email
Click Send Email (You'll get 2 Message boxes)

Then if you:

Refresh the page
Manually clear each text box
Click Send Email (You'll only get 1 Message box)

Then if you refresh and revert to the 1st set of steps, back to 2 boxes. Weird, yes?

BTW, still learning here. I hadn't checked this previously, it works fine on my local host, of course. But at my hosting location I find I can not add pictures to an album I create. I received an error email from the site (thank you very much!) that said:


Access to the path 'G:\PleskVhosts\wbctech.net\wrox.wbctech.net\GigPics\dca027b6-cef4-40d8-b898-bacb405df49b.jpg' is denied.
I will reach out to the hosting provider, but thought you may have some comments of wisdom about this error. It seems like my hosting provider isn't allowing my site to have uploads in its current configuration. Am I reading this correctly?

Best Regards,

Imar March 6th, 2014 07:19 AM

Try setting CausesValidation on the Reset button to False and see if that helps.

For the images issue: check that the folder exists, and make sure the permissions in the server are OK. Chapter 19 has more details.



All times are GMT -4. The time now is 01:08 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.