ASP.NET Gripe #2

Three posts in one morning? Wow. I’d meant to post this earlier, but with one thing and another…
ASP.NET renames your controls.
I discovered this while, once again, working with the dreadful ITS component of SAP. It needs fields named TABLE_NAME-FIELD_NAME. Note the hyphen. Obviously, if you try to create a control with that Id, .NET complains. So I did the following:
<input type="hidden" name="TABLE_NAME-FIELD_NAME" id="TABLE_NAME_FIELD_NAME" runat="server">
So it’s got a .NET compatible Id but an ITS-compatible name. Great solution, huh?
No. I couldn’t get it working. ITS wasn’t picking up the value coming through from the fields. When I viewed the HTML generated by my page I found out why:
<input type="hidden" name="TABLE_NAME_FIELD_NAME" id="TABLE_NAME_FIELD_NAME" runat="server">
In other words, it changed the name of my control to make it match the id. Now I can kind of understand that. When a form submits, you get name-value pairs on the server side, and .NET would obviously prefer to have the id matching the name. On the other hand, RadioButton controls already have a different id to the name, so why can’t .NET be clever enough to deal with other controls doing the same?
Anyway. I came up with a rather hacky solution to this one. My HTML now looks like this:
<input type="hidden" ProperName="TABLE_NAME_FIELD_NAME" id="TABLE_NAME_FIELD_NAME" runat="server">
…and I have some JavaScript that runs before the form is submitted that loops through the form elements looking for items with a ProperName attribute, and putting its value in the name field instead.
This is a fairly minor gripe. After all, .NET assumes you’re calling other .NET pages rather than redirecting output to a hideously rubbish system like ITS, and nothing else uses such stupid names for its fields. Still. Leave my HTML alone!
This entry was posted in Computers and Internet. Bookmark the permalink.

1 Response to ASP.NET Gripe #2

  1. Hayley says:

    loving the space!please check mine out as I am building a new anti-bullying website, and need all the feedback I can get. Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s