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();");
Sign up to request clarification or add additional context in comments.

1 Comment

I modified my answer with a response.
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" />

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.