DropDownLIst populated by xml file works in IE but not Firefox

  • Thread starter Thread starter William LaMartin
  • Start date Start date
W

William LaMartin

On an aspx page, I place ASP.Net controls of a DropDownList, a button and a
label. The DropDownList is populated from an xml file . When the button is
clicked the selected value of the DropDown List is displayed in the label.

All very simple, and it works fine in Internet explorer, but in Firefox
simply changing the selection in the DropDownList produces the error listed
below. I have done a bit of web searching and found reasons for this but
the suggested solutions(or ant least my implementation of them) do not work
for me.

Any Ideas?

My code

Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not (IsPostBack) Then
Dim ds1 As New Data.DataSet
ds1.ReadXml(Server.MapPath(".") & "\App_Data\States.xml")
Me.ddlState.DataTextField = "Name"
Me.ddlState.DataValueField = "Name"
Me.ddlState.DataMember = "State"
Me.ddlState.DataSource = ds1.Tables(0)
Me.ddlState.DataBind()
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Me.Label1.Text = Me.ddlState.SelectedValue
End Sub

End Class



The error:

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.
 
On an aspx page, I place ASP.Net controls of a DropDownList, a button anda
label. The DropDownList is populated from an xml file . When the button is
clicked the selected value of the DropDown List is displayed in the label..

All very simple, and it works fine in Internet explorer, but in Firefox
simply changing the selection in the DropDownList produces the error listed
below.  I have done a bit of web searching and found reasons for this but
the suggested solutions(or ant least my implementation of them) do not work
for me.

Any Ideas?

My code

Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not (IsPostBack) Then
Dim ds1 As New Data.DataSet
ds1.ReadXml(Server.MapPath(".") & "\App_Data\States.xml")
Me.ddlState.DataTextField = "Name"
Me.ddlState.DataValueField = "Name"
Me.ddlState.DataMember = "State"
Me.ddlState.DataSource = ds1.Tables(0)
Me.ddlState.DataBind()
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Me.Label1.Text = Me.ddlState.SelectedValue
End Sub

End Class

The error:

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.

Hi William

I hope you don't mind my mentioning this but your application the
MapPath() method is a bit odd. It is mean't translate URL address
paths to local path syntax. All you need is this:

ds1.ReadXml(Server.MapPath("~/App_Data/states.xml"))

Also, there is no need to prefix everything with "Me." All controls on
the current page are in scope by reference to the instance name alone.

Not sure what is causing your problem but it sounds like your
installation of FireFox is the culprit not your code. Try re-
installing it or maybe clearing the cache (delete tempoary files).
 
A bit more research has revealed that Firefox does not like you to populate
a dropdown in asp.net from a file as I did. It is considered a security
threat for some reason (something to do with possibly seeing different
things on postback than what was there originally). So the simple solution
is just to explicitly (in code) add each of the items I want to the
dropdown. People claimed to have workarounds to this, but nothing that I
could get to work.

I am pretty sure, if you put an asp.net dropdownlist on a webform and
populate it from a file, you too will have a problem in Firefox but not in
IE.

I preface objects with me, since then the Intellesense keeps me from having
to worry about spelling.

As to the Server.Map.Path("."), that has worked well for me for years, but
have noticed that almost everyone else uses your approach.

On an aspx page, I place ASP.Net controls of a DropDownList, a button and
a
label. The DropDownList is populated from an xml file . When the button is
clicked the selected value of the DropDown List is displayed in the label.

All very simple, and it works fine in Internet explorer, but in Firefox
simply changing the selection in the DropDownList produces the error
listed
below. I have done a bit of web searching and found reasons for this but
the suggested solutions(or ant least my implementation of them) do not
work
for me.

Any Ideas?

My code

Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load
If Not (IsPostBack) Then
Dim ds1 As New Data.DataSet
ds1.ReadXml(Server.MapPath(".") & "\App_Data\States.xml")
Me.ddlState.DataTextField = "Name"
Me.ddlState.DataValueField = "Name"
Me.ddlState.DataMember = "State"
Me.ddlState.DataSource = ds1.Tables(0)
Me.ddlState.DataBind()
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Me.Label1.Text = Me.ddlState.SelectedValue
End Sub

End Class

The error:

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.

Hi William

I hope you don't mind my mentioning this but your application the
MapPath() method is a bit odd. It is mean't translate URL address
paths to local path syntax. All you need is this:

ds1.ReadXml(Server.MapPath("~/App_Data/states.xml"))

Also, there is no need to prefix everything with "Me." All controls on
the current page are in scope by reference to the instance name alone.

Not sure what is causing your problem but it sounds like your
installation of FireFox is the culprit not your code. Try re-
installing it or maybe clearing the cache (delete tempoary files).
 
Back
Top