UpdatePanel - Show errors from server-side into client side div

I have an updatePanel with asp:button inside it. Now on the button click, I am doing validations and wants to print the message to the screen. I want to show the message in the client side <div>.

I was hoping that I can leverage the EndRequest method of the PageRequestManager class to print the messages in the <div>.

Is there a way I can throw the error messages to the async error message and then pull it from the EndRequest method?

Pls suggest any approach.

I tried following the article given by Microsoft:- http://msdn.microsoft.com/en-us/library/bb398934.aspx

This article works with the standard error messages, but I want to make it work with my custom error messages.

Answers


Add a javascript call to you validation call from server and pass the error/s string in the call and update the DIV on the client.

Example:

function ShowError(msg)
{
  $get('divError').innerHTML = msg;
}

On the Server

public btn_click(object sender,EventArgs e)
{
string Errors = "";
//Validation Block;
string script = "ShowError('(0}')";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "",  string.Format(script,Errors),true);
}

I hope this helps; Please make sure you properly Encode the ErrorMessage to avoid missing literal errors on client end


Need Your Help

Rails 3 session & cookie how to persist session id cookie

ruby-on-rails session cookies

I am developing a simple shopping cart based on session_id i.e. for determination of a user cart items used session_id.

vba that search for a value if it matches find closest date

vba date find next

i wrote a code for a workbook that have two worksheet´s, in the ProximoPedido (sheet) in column "A" there is a range of a values (integer number) and in colunm "B" there is a date associated, and i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.