ValidateEvent bug with table and radio button

P

Peter Kuijt

ValidateEvent throws an argument exception when it should not:

make a new ASP.Net (2.0) web site and paste this code in Page_Load():
//-----
Button button = new Button();
button.Text = "Submit";
form1.Controls.Add(button);

Table table = new Table();
table.ID = "theName";
form1.Controls.Add(table);

HtmlInputRadioButton r1 = new HtmlInputRadioButton();
r1.ID = "R1";
r1.Name = "theName";
form1.Controls.Add(r1);
//------

The table ID and the radio button Name are the same.
Start the web site, select the radio button and click the submit button, the
trace below follows.
To my surprise this is fixed by adding the MyTable() definition:

public class MyTable : Table {
public MyTable() : base() { }
}

and replace:
Table table = new Table();
by:
Table table = new MyTable();

This looks like a bug to me...

--Peter

Trace:

[ArgumentException: Invalid postback or callback argument. Event validation
is enabled using <pages enableEventValidation="true"/> in configuration or
<%@ Page EnableEventValidation="true" %> in a page. For security purposes,
this feature verifies that arguments to postback or callback events
originate from the server control that originally rendered them. If the
data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to register
the postback or callback data for validation.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String
argument) +367
System.Web.UI.Control.ValidateEvent(String uniqueID, String
eventArgument) +83
System.Web.UI.WebControls.Table.RaisePostBackEvent(String argument) +51
System.Web.UI.WebControls.Table.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837
 
C

CaffieneRush

Name and id serve the same purpose - that of identifying the tag.
Normally, you only use one and not another.
Quote w3c: "Note that in XHTML 1.0, the name attribute of these
elements is formally deprecated, and will be removed in a subsequent
version of XHTML."

Perhaps Microsoft following the w3c recomendations on the use of id and
name attributes by treating them as the same and this is perhaps the
cause of your problem.
http://www.w3.org/TR/xhtml1/#h-4.10
 
P

Peter Kuijt

Name and id serve the same purpose - that of identifying the tag.
Normally, you only use one and not another.
Quote w3c: "Note that in XHTML 1.0, the name attribute of these
elements is formally deprecated, and will be removed in a subsequent
version of XHTML."

Perhaps Microsoft following the w3c recomendations on the use of id and
name attributes by treating them as the same and this is perhaps the
cause of your problem.
http://www.w3.org/TR/xhtml1/#h-4.10

Hmm, replacing HtmlInputRadioButton by a HtmlInputCheckBox in my example has
no problems

--Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top