ASP.NET development, several ways to add client code

zhaozj2021-02-16  53

In the development of ASP.NET, we often use client code, such as JavaScript

Of course, you can embed in HTML. But here is what the server is dynamically added to the client to add client code.

1. Use the RegisterClientScriptBlock method for the Page control:

DIM S as string = ""

S = "functon alertmsg () {"

S = "Alert (" Error ");}"

S = ""

IF (Not is ClientscriptBlockRegistered ("XXX")).

RegisterClientScriptblock ("xxx", s)

END IF

Add to Button's Click event to the server side:

Button.attributes.add ("onclick", "alertmsg ()")

This way, you can add this JavaScript code to the client.

2. When running, the client code is added directly by adding the properties of the control.

Such as:

Button.attributes.add ("onclick", "Alert ('Error!');")

Both methods can achieve the same effect.

转载请注明原文地址:https://www.9cbs.com/read-23488.html

New Post(0)