How do we call the client script from the server side of the asp.net script?

What do we call the client script from the server side of asp.net script?

+3
source share
6 answers

You can try the code below:

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString("N"), "alert('ok');", true);
+6
source

:

  Page.ClientScript.RegisterStartupScript(Type, String key, String script) 

  Page.ClientScript.RegisterClientScriptBlock(Type, String key, String script)

"" "" script. , script, . , ,

.

      1.RegisterClientScriptBlock()  method add the script before the controls are renderd in the page. So the scripts we are registered can't acess the controls inside the page. 


      e.g : var name = document.getElementById('txtName');  //will not work as excepted.



      2.RegisterStartupScript() method add the script before the end of body tag after all the controls are rendered in the browser. So the registered script can acess the controls inside the page .


      e.g : var name = document.getElementById('txtName');  //will work fine.
+3

.

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "alert('Test Event');", true);
+1

Insert a button and double-click it.

Add this property: Runat = "server"

In your code behind the file, write this code:

Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript",
    "document.getElementById('Button').style.visibility = 'visible';" ,true);
0
source

You can do this by adding a button and any event on that button as your requirement.

Suppose you want to delete a text field after inserting a row.

Then you simply double-click on this button and go to this file for the code and simply enter the code, for example:

txtbox1.text = null;

after each click event, your text box is empty automatically

0
source

Source: https://habr.com/ru/post/1746832/


All Articles