Friday, April 6, 2007

Hide Error Label on Body On-Load.

Below is to show how the Labels are used to show errors.


Declaratively we make the Label as Visible. Otherwise it won’t be accessible thru Javascript.


<asp:Label ID="Label1" runat="server" Text="Error Label" ForeColor="Red" Visible="true"></asp:Label>


But at first time the Page loads, we definitely would not like to show the error label. Hence we will make it invisible thru JavaScript using below.


<script language="javascript">   

        window.onload=function() {HideMe();}       



Now when first time the Page Loads below happens:

þ      Page_Load

þ      Page_PreRender

þ      body_onload_clientside : This hides Label again by calling above script.

þ      Page_Render

þ      Page_Unload


Now let’s say we have a button having an attached JS call. If JS script return true we need to call Server Side otherwise Error label should become visible,

<asp:Button ID="Outer" runat="server" OnClick="Button1_Click" OnClientClick=" return Validate();" Text="Outer" />

Below sequence fires.

  • When the button is clicked below event happens:
    • button_clientside_click :
      • If return false then the Error label will become visible and no server side event will occur.
      • If return true, then the flow will be redirected to server and below event happens.
        • Page_Load: Label gets Visible here using the declarative values.
        • Button_ServerSide_Click : Sleeps thread for 2 secs.
        • Page_PreRender
        • body_onload_clientside : This hides Label again by calling 'window.onload="Hide();'
        • Page_Render : Label gets In-Visible.
        • Page_Unload

// ------------------------------------------------
function Hide()

function UnHide()


function Validate()


            var response=CheckValidation();



                return true;





                return false.



// ------------------------------------------------

Hope it is Clear.



Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice - Bridgestone - Tyre Link || Persistent Systems


DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

No comments:

Post a Comment