Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 28th, 2014, 04:06 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default 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?

Thanks.

Best Regards,
Alan
  #2 (permalink)  
Old January 28th, 2014, 04:21 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old January 28th, 2014, 05:36 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default

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,
Alan
  #4 (permalink)  
Old January 29th, 2014, 05:30 AM
EricCulbertson
Guest
 
Posts: n/a
Default

surely, your coding is playing up with you why you are not getting the right outcome
Received Infraction
  #5 (permalink)  
Old January 29th, 2014, 10:17 AM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default

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,
Alan
  #6 (permalink)  
Old February 17th, 2014, 06:40 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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:
Code:
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.
Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Path="~/Scripts/WebForms/WebUIValidation.js" />
</Scripts>
</asp:ScriptManager>
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!).

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #7 (permalink)  
Old March 3rd, 2014, 03:27 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default 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?

Thanks.

Best Regards,
Alan
  #8 (permalink)  
Old March 5th, 2014, 06:49 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #9 (permalink)  
Old March 5th, 2014, 03:48 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default

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:

Code:
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,
Alan
  #10 (permalink)  
Old March 6th, 2014, 07:19 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 11 jQuery animating the Contact Form Try it Out AlanWheeler BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 January 28th, 2014 03:38 PM
Ch 11 jQuery install - packages.config error AlanWheeler BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 January 28th, 2014 11:55 AM
Chapter 11 - jQuery slynn BOOK: Beginning ASP.NET 4.5 : in C# and VB 4 September 24th, 2013 01:48 PM
Problem with jquery ch 11 nzg5 BOOK: Beginning ASP.NET 4 : in C# and VB 16 February 25th, 2012 10:49 PM
Problem with jquery ch 11 nzg5 BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 4th, 2010 11:57 AM





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