Sys.WebForms.PageRequestManagerParserErrorException – what it is and how to avoid it

Sys.WebForms.PageRequestManagerParserErrorException – what it is and how to avoid it

If you’ve used the Microsoft ASP.NET AJAX UpdatePanel control, there’s a good chance you’ve hit the “Sys.WebForms.PageRequestManagerParserErrorException” error.

What’s a PageRequestManagerParserErrorException?

The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server. Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often). Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts.

As I mentioned, this is rendered out using a special format that the JavaScript on the client can understand. If you mess with the format by rendering things outside of the render phase of the page, the format will be messed up. Perhaps the most common way to do this is to call Response.Write() during Page’s Load event, which is something that page developers often do for debugging purposes.

The client ends up receiving a blob of data that it can’t parse, so it gives up and shows you a PageRequestManagerParserErrorException. Here’s an example of what the message contains:

—————————
Microsoft Internet Explorer
—————————
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near ‘Hello, World!106|upd’.
—————————
OK
—————————

If you ask me, this error message is not all that bad. After all, I’m the one that made it :) The details indicate what was being parsed when it decided to give up. You can see the part of the text from my Response.Write(), and immediately after that is part of the special format I keep mentioning.

Why do I keeping getting a PageRequestManagerParserErrorException?

Well, chances are you’re doing one of the things mentioned in the error message. Here are the most common reasons and why they don’t work:

1.

Calls to Response.Write():
By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly…). This means that UpdatePanel can’t encode the data in its special format.
2.

Response filters:
Similar to Response.Write(), response filters can change the rendering in such a way that the UpdatePanel won’t know.
3.

HttpModules:
Again, the same deal as Response.Write() and response filters.
4.

Server trace is enabled:
If I were going to implement trace again, I’d do it differently. Trace is effectively written out using Response.Write(), and as such messes up the special format that we use for UpdatePanel.
5.

Calls to Server.Transfer():
Unfortunately, there’s no way to detect that Server.Transfer() was called. This means that UpdatePanel can’t do anything intelligent when someone calls Server.Transfer(). The response sent back to the client is the HTML markup from the page to which you transferred. Since its HTML and not the special format, it can’t be parsed, and you get the error.

How do I avoid getting a PageRequestManagerParserErrorException?

To start with, don’t do anything from the preceding list! Here’s a matching list of how to avoid a given error (when possible):

1.

Calls to Response.Write():
Place an or similar control on your page and set its Text property. The added benefit is that your pages will be valid HTML. When using Response.Write() you typically end up with pages that contain invalid markup.
2.

Response filters:
The fix might just be to not use the filter. They’re not used very often anyway. If possible, filter things at the control level and not at the response level.
3.

HttpModules:
Same as response filters.
4.

Server trace is enabled:
Use some other form of tracing, such as writing to a log file, the Windows event log, or a custom mechanism.
5.

Calls to Server.Transfer():
I’m not really sure why people use Server.Transfer() at all. Perhaps it’s a legacy thing from Classic ASP. I’d suggest using Response.Redirect() with query string parameters or cross-page posting.

Another way to avoid the parse error is to do a regular postback instead of an asynchronous postback. For example, if you have a button that absolutely must do a Server.Transfer(), make it do regular postbacks. There are a number of ways of doing this:

1.

The easiest is to simply place the button outside of any UpdatePanels. Unfortunately the layout of your page might not allow for this.
2.

Add a PostBackTrigger to your UpdatePanel that points at the button. This works great if the button is declared statically through markup on the page.
3.

Call ScriptManager.RegisterPostBackControl() and pass in the button in question. This is the best solution for controls that are added dynamically, such as those inside a repeating template.

Categories: Uncategorized

My new project using MVC

November 10, 2009 Leave a comment

i use my free time to create ASP.NET MVC content management portals

Still developing now

here i post a screen shot to my blog

adminportals

new update today

add article page

update

Categories: .NET 2.0

TUTORIAL: How to install PHP and MySQL on IIS

With the apparent increase of interest in individuals desiring to install PHP and MySQL on computers running Windows operating systems, I thought it would be beneficial to provide a set of instructions to help make this process as easy as possible. In this article, I’ll be providing some basics of IIS installation and then move to the installation of PHP and MySQL.

Some essentials you will need to get started:
IIS (preferably IIS 5 or IIS 6)
The PHP windows installer file
The PHP binaries file
The MySQL Windows installation file
(links will be provided for the downloads shortly).

Optional:
phpMyAdmin
MySQL Administrator

Let’s get started. Since you are installing on a Windows computer, you will most likely be using IIS for a web server, however, it is not required. You must have some web server running however, and you are quite welcome to use Apache or another web server of your choice, however, since that falls outside the scope of this tutorial we will leave that discussion for another day.

Some things to know about IIS. IIS v5.1 is included with Windows 2000 Professional, and Windows XP Professional, but is not installed by default. (*note – IIS 5.1 is not included with XP Home edition and is not available as a stand alone download from Microsoft. If you are an XP Home user, you will need to look for an alternative web server solution.) Windows 2000 server includes IIS 5.1, and Windows 2003 server includes IIS 6.

If you haven’t already done so begin by installing IIS. To do this go to Control Panel | Add/Remove Programs | Add/Remove Windows Components. In the dialogue box that comes up, check the option for Internet Information Services(IIS) and click the “Details” button. Select any additional features that would like to have installed and click OK. Click OK again to begin the installation. This will install IIS and start the web server service automatically. You should not need to reboot. To test your installation open your web browser and type in

http://localhost/

. This should bring up the default IIS page. If it does, your installation was a success and you can immediately get started on installing PHP.

It really shouldn’t matter whether you install PHP first or MySQL first. I’ve simply gotten into the habit of beginning with PHP, so that will be my next step. To get the files you will need, go to the download page at php.net . The most current release available for download at the time of this writing is 5.1.1. This release has worked just fine for me, so it’s the one I use. You will want to download both the PHP 5.1.1 zip package AND the PHP 5.1.1 installer. Unzip both files to a temporary location and run the setup installer. This will install PHP automatically. The default installation directory is C:\PHP and I would suggest to leave it at that, unless there is a specific reason you need to install it elsewhere. *note it is not recommended to install PHP in a directory that contains spaces such as c:\Program Files\PHP as it can cause some web servers to crash. Answer the questions as they are presented by the wizard. I recommend choosing the option to add PHP to the Windows PATH environment variable when that option is presented. If not you can manually add it later, but you really should include it. For a good article on Windows environment variables go here . When the installer completes you will have a basic installation of PHP. This works just fine, but it is recommended to add the additional libraries found in the PHP 5.1.1 zip package. Simply copy those files into the C:\PHP directory. The following files in this package are already installed with your PHP and there is no need to copy them install.txt, license.txt, php.exe and php4ts.dll.

To test your PHP installation copy the following into a file and save it as info.php in c:\Inetpub\wwwroot\ . (wwwroot is Windows IIS default website folder. Any of your web files will always go in there)

//

Code: [ Download ] [ Select ]//
<?php phpinfo(); ?>


Then go to your web browser and type: http://localhost/info.php

. If your installation was successful, this should display your PHP configuration information.

Now we can proceed to installing MySQL. Go to the MySQL download page here. . As of this writing the most current release is v5.0.16. Download the Windows(x86) file (the 33.6MB file). This is the full package and includes the installer. Unzip it to a temporary location and run the installer. For the most part, especially for someone doing this the first time, it’s easiest to use the standard installation. This will essentially configure all the basic things you need to have MySQL work. During the configuration you will be asked which port to use. The default port 3306 is usually fine, however if you know something else is already using that port, you can select another one. Your “super” user that will be created during the install is user “root”. Root is the chief administrative username and can do anything in MySQL. You can add other users later after you’re up and running, but root is going to be your main admin access. Remember the root password you use. If you lose or forget it, there is no way to access it, and you could find yourself unable to use MySQL. Complete the wizard. Now let’s test it to make sure it’s working. Go to Programs | MySQL | MySQL Server 5 | MySQL Command Line Client. This is a utility similar to DOS for managing MySQL. At the password prompt type in the password you entered and hit enter. If your server is working properly you should get something that looks like this:

Quote:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.16-nt

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>

If you see that, your installation was successful. You can type quit or exit to close the Client.

Now there are some purists out there that probably swear by that command line client and use it exclusively for managing their server. However, for us spoiled Windows dummies that are used to “easy-to-use” GUI’s there is an alternative good tool for your server management – MySQL Administrator which can be downloaded from HERE . The installation is very straightforward. After it’s installed simply run it. For your logon the host would be localhost, the port would be the port you used when installing MySQL (default 3306) and the user would be root with the password you gave on installation. Since administering your MySQL server is beyond the scope of this article, we’ll leave that for another day, however, you’ll see very quickly the ease with which you can add users and create and manage your databases.

The last tool that I listed as optional, I actually couldn’t live without it, and that is phpMyAdmin which can be downloaded HERE . Simply unzip the contents to a temporary directory. Create a folder called phpMyAdmin in c:\Inetpub\wwwroot\ and copy your extracted phpMyAdmin download files in there. Then open config.default.php in an editor and edit the following as needed.
Make sure the port number here $cfg['Servers'][$i]['port'] = ’3306′; matches the port you used when installing MySQL. If you are going to only be using this as a development machine and it will not be connected to the internet or accessible from the internet use the following configuration for these three lines:

//

Code: [ Download ] [ Select ]// Line Numbers Off ]
$cfg['Servers'][$i]['auth_type']     = ‘config’; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user']         = ‘root’;     // MySQL user
$cfg['Servers'][$i]['password']     = ‘yourpassword’;         // MySQL password (only needed
// with ‘config’ auth_type)
  1. $cfg['Servers'][$i]['auth_type']     = ‘config’; // Authentication method (config, http or cookie based)?
  2. $cfg['Servers'][$i]['user']         = ‘root’;     // MySQL user
  3. $cfg['Servers'][$i]['password']     = ‘yourpassword’;         // MySQL password (only needed
  4. // with ‘config’ auth_type)

If this will be accessible from the web, you’ll most likely want to use HTTP authentication, in which case change config to http and leave user and password empty. Save the file as config.inc.php in your phpMyAdmin folder.

For some reason on a Windows machine, phpMyAdmin seems to want access to php_mbstring.dll . To solve this open c:\Windows\php.ini (or WINNT if Win2K) and find the following:
; Directory in which the loadable extensions (modules) reside.
extension_dir = “./’
Change that to
; Directory in which the loadable extensions (modules) reside.
extension_dir = “./extensions/”

Then scroll down to this line and uncomment it (remove the leading semi-colon)
extension=php_mbstring.dll

Now, in theory you should be able to go to

http://localhost/phpMyAdmin/index.php

and you should be working. “In Theory”. However, I’ve done four Windows installations on Win2K, XP and Windows 2003 Server machines, and this is where I always run into a snag. For some reason, there seems to be a bit of a problem with the MySQL authentication protocol that it doesn’t like. Since one of our members recently had this problem and rather than retyping everything, simply read the post here for the workaround to this:

ftopic55568.html

Categories: Uncategorized

Onlineshopping design

working

Categories: .NET 2.0

Web design

working

Categories: Design

Some good video websites to catch with Microsoft technology

September 23, 2009 Leave a comment

Although all the videos are from last year , but they are still good and if you missed the teched you can catch up there.
http://www.microsoft.com/emea/msdn/spotlight/

http://www.microsoft.com/emea/spotlight/

Categories: Uncategorized

My working

September 18, 2009 Leave a comment
Categories: Design

Made a Form Validator and add CSS style make it looks better

September 17, 2009 Leave a comment
Categories: Uncategorized Tags:

Send Email using CSharp via Gmail

September 9, 2009 Leave a comment

Namespaces

The following Namespaces need to be imported in order to send emails

using System.Net;

using System.Net.Mail;


MailMessage Class Properties

Following are the required properties of the mail message class.

From – Sender’s email address

To – Recipient(s) Email Address

CC – Carbon Copies

BCC – Blind Carbon Copies

Subject – Subject of the Email

Body – Body of the Email

IsBodyHtml – Specify whether body contains text or HTML mark up.

Attachments – Attachments if Any.

ReplyTo – ReplyTo Email address.


Creating a MailMessage Object

MailMessage mm = new MailMessage();

mm.From = new MailAddress(“username@gmail.com”);

mm.Subject = “Hello”;

mm.Body = “<p>Body</p>”;

mm.IsBodyHtml = true;


SMTP Class Properties

Following are the properties of the SMTP class.

Host – Your SMTP Server

EnableSsl – Specify whether you host accepts SSL Connections.

UseDefaultCredentials – Set to True inorder to allow authentication based on the Credentials of the Account used to send emails

Credentials – Valid login credentials for the SMTP server

Port – Port Number of the SMTP server

Below code describes how the above properties are applied

smtp.Host = “smtp.gmail.com”;

smtp.EnableSsl = true;

System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

NetworkCred.UserName = “username@gmail.com”;

NetworkCred.Password = “xxxxxxxxx”;

smtp.UseDefaultCredentials = true;

smtp.Credentials = NetworkCred;

smtp.Port = 587;


Send Email

The method Smtp.Send(..) is used to send the email. See the example below


smtp.Send(mm);


MessageBox.Show(“Message sent successfully.”,”Success”, MessageBoxButtons.OK,MessageBoxIcon.Information);


Send Email Asynchronously

//Create event handler

void sc_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
Console.WriteLine(“Message cancelled”);
else if (e.Error != null)
Console.WriteLine(“Error: ” + e.Error.ToString());
else
Console.WriteLine(“Message sent”);
}

//Add event handler

smtp.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);

smtp.SendAsync(mm , null);

//Or Cancel the transmtion

smtp.SendAsyncCancel();


Send Email using Background Thread

Sending Email requires some amount of time. So many times user has to wait for the page to load while the mail is being sent. And if the server is not reachable the code will try to send email until timeout.

To avoid that the email can be sent using a background thread and the user can be displayed a message immediately without delay.

Import the following Namespace

using System.Threading;

Send email using a Background thread

Thread threadSendMails;

threadSendMails = new Thread(delegate()

{

sendemail(“username@gmail.com”, “receiver@abc.com”, “Hello”, “<p>Body</p>”, “C:\\MyDoc.txt”, true);

});

threadSendMails.IsBackground = true;

threadSendMails.Start();

Categories: .NET 2.0
Follow

Get every new post delivered to your Inbox.