Subscribe to Subscribers

Forums » .NET » JavaScript »

ClientScript.RegisterStartupScript & btn.Attributes.Add("onclick", "return sampleValidati


Posted Date: 21 Jul 2012      Posted By:: Ali     Member Level: Gold    Member Rank: 579     Points: 2   Responses: 2




we can javascript from Server side by
ClientScript.RegisterStartupScript & btn.Attributes.Add("onclick", "return sampleValidation)






when do we prefer the each one in which situation?





Responses

#681321    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 21/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

The first one i.e. ClientScript.RegisterStartupScript can be used to execute some JavaScript, anywhere in the page. For example, if you want to fire an alert window from server side you can use the above from anywhere on the page.
The later one is used to attach a click attribute to an ASP button; you generally perform this operation either in page load or achieving some condition. The attached attribute (in this case click) would be bound to the button and gets executed only when the button gets clicked.

Hope it'll help you.
Regards
Ajatshatru


 
#681580    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 23/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,


Refer belowww.

From server side to call javascript functions/Javascript at a particular point we use ClientScript.RegisterStartupScript .

Ex:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('The Field is mandatory');", true);

And btn.Attributes.Add("onclick", "return sampleValidation)
On click of button if we want to execute any javascript function from server side we use this.
Both we use in code behind.




Hope this will help you

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too


 
Post Reply
You must Sign In to post a response.

Next : Restoring the Vitality and Well Being of the Body
Previous : Null Validation without Alert Box
Return to Discussion Forum
Post New Message
Category:

Related Messages

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.