1

It appears that ASP.NET WebForms automatically sets the values of the name and value attributes with the value of the ID attribute for an asp:Button. How dou you set custom values for those attributes? I tried it with MyButton.Attributes["name"] = "CustomName"

but then i have two name attributes in generated html.

I would like to use custom values to determine which button was clicked during a postback. I don't want to use CommandName or CommandArgument because when a postback occurs I just want to check for name and value. I don't want to care about whether a handwritten input element

(like <input type="submit" name="buttons" value="abc"></input>)

caused the postback or a input element generated by asp.net

0

1 Answer 1

4

You can use ClientIDMode property to static. However, you need to make sure that ID is unique within a page.

ASPX

<asp:Button runat="server" ID="CustomButton" Text="abc" ClientIDMode="Static" />

Render HTML

<input type="submit" name="CustomButton" value="abc" id="CustomButton" />
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately this requires ASP.NET 4. I use 3.5.

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.