0

What the Attributes collection property for ASP.NET controls/forms are used for?

Can we use this property for achieving the same functionality as RegisterStartupScript() ?

2 Answers 2

1

It's used for adding client-side attributes to a server-side control. For instance:

ButtonSubmit.Attributes.Add("onclick", "return confirm('Are you sure?');");

If you can get a reference to the HTML page's body tag, you should be able to do the same thing by adding an attribute like so:

BodyTag.Attributes.Add("onload", "myJavaScriptFunction();");
1
1

You can add attributes to a control that gets output as html.

So for this C# code:

ButtonSubmit.Attributes.Add("onclick", "return confirm('Are you sure?');");

Something like this html will be output:

<input type="button" onclick="return confirm('Are you sure?');" value="Submit" />
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.