开发者

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

开发者 https://www.devze.com 2023-03-15 02:02 出处:网络
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 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, bu开发者_如何学JAVAt I want to make it work with my custom error messages.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号