Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegisterClientScriptBlock parameters usages in real scenarios?

http://i.stack.imgur.com/dVjHt.jpg

enter image description here

I never understood the real usage of the Control , type,key usages of this class.

In general Ive always used with : this , GetType() , "xx"

but now I truly want to understand .


msdn :

Control : " the control that is registering the client script"

so...? what difference does it makes who registered it ? the script will be in the head of the page...

Type: "the type of the client script block"

type ??? its javascript. why does he want another type from me ?

Key: "a unique indentifier"

That I can understand - for cases which later to remove... but I'd love for some more advanced explanations

Can I have please , a real life scenario in which I TRULY have to play with those params ?

like image 489
Royi Namir Avatar asked Nov 28 '11 16:11

Royi Namir


People also ask

When to use RegisterClientScriptBlock?

You use the RegisterClientScriptBlock method to register a client script block that is compatible with partial-page rendering and that has no Microsoft Ajax Library dependencies.

What is the use of RegisterStartupScript?

RegisterStartupScript(Control, Type, String, String, Boolean) Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.

What is the use of page ClientScript RegisterStartupScript?

ClientScript. RegisterStartupScript for displaying alert messages. it works fine for the first message, however second message wont display. Though it passes through the code while debugging.


1 Answers

the most important part is Control which control in html tags you want to register the script for example if you have user control and you want to run the script just for that use this line

ScriptManager.RegisterStartupScript(this, this.GetType(), "alertscript", "document.getElementById('userControl_h1TAG')", true); 

but when you want to register the block and script to all part of that page use this line in CS code of user-control :

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alertscript", "document.getElementById('page_h1TAG')", true);
like image 189
Mojtaba Pourmirzaei Avatar answered Sep 22 '22 17:09

Mojtaba Pourmirzaei