You all might aware of that in win forms you might have used Message.Show("Some Text") to show some information. However in Asp.net forms you might have used Alert( ) or used a Literal or Label to Show some Message when you want to show some thing to the user like 1) Your Resume has been updated Successfully. or 2) User Created Successfully or 3) A mail has been sent to your Mail ID and so on. In above all case the best one is to be go for a Literal or a Label and show the message there. How ever you want to show a message like alert using Literal, then go for the code below:
public static void ShowMessage(Page page,string message)
{
Literal literalMessage=new Literal( );
literalMessage.Text="<script>alert('" + message + " ')</script>";
page.Controls.Add(literalMessage);
}
How we can use the above code :-
Just think that we want some message on a button click event,then we can use it as:
protected void btnSave_Click(Object sender, EventArgs e)
{
ShowMessage(this, "Data updated Successfully!");
}
Enjoy it...........
No comments:
Post a Comment