已在javascript中修改的控件的回发 [英] Postback of controls which have been modified in javascript

查看:71
本文介绍了已在javascript中修改的控件的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个用于管理任务列表的应用程序,我正在尝试将一些

控件添加到我可用于链接任务的表单中,我的初衷是

是: -


添加两个列表框,一个列表所有任务和另一个列表

链接任务,我有两个按钮,在javascript中将项目从

第一个列表移动到第二个。

然后,当用户点击thrid按钮时,我想保存这些数据。


然而,第一个问题是事件验证器抛出了一个摇摆不定的

并拒绝了我的回发。


我关闭了页面的EventValidation。


然后我注意到控制状态是和我在表格中加载
时一样。即使我改变了ListBox的内容?


希望这是有道理的,这是漫长的一天!


TIA

MC

I''m writing an app for managing Task Lists, I''m trying to add some
controls to a form that I can use to link tasks, my original intention
was to: -

Add two list boxes, one listing "all Tasks" and the other listing
"Linked Tasks", I have two buttons which in javascript move items from
the first list into the second.

Then when a user clicks a thrid button I would like to save this data.

however, the first problem was that the Event Validator threw a wobly
and rejected my postback.

I turned off EventValidation for the page.

I then noticed that the control state was the same as it was when I
loaded the form. even though I changed the contents of the ListBox?

Hope this makes sense, it''s been a long day!

TIA
MC

推荐答案

之前我做过类似的事情,需要一点点处理。

首先,创建一个隐藏控件(< input type =" hidden" name =" MyHiddenItem" />

(确保你给它一个名字属性))存储您的链接任务列表框中的值。然后,在表单提交事件中,将链接任务列表框中的

值存储为隐藏的

控件中的逗号分隔列表。最后,在服务器端,检查Request.Form集合以获取链接任务列表框的

值。这应该给你你想要的东西。


现在不要摇摇晃晃! :)

Jim


" mc" < mc@community.nospamwrote in message

news:45 ******** @ mail.hmgcc.gov.uk ...
I''ve done similar things before, and it requires a little bit of process.
First, create a hidden control (<input type="hidden" name="MyHiddenItem" />
(make sure you give it a name attribute)) to store the values that are in
your Linked Tasks listbox. Then, on your form submit event, store the
values from the Linked Tasks listbox as a comma-delimited list in the hidden
control. Finally, server-side, check the Request.Form collection for the
Value of your Linked Tasks listbox. This should give you what you want.

Don''t get wobbly, now! :)
Jim

"mc" <mc@community.nospamwrote in message
news:45********@mail.hmgcc.gov.uk...

我正在编写一个用于管理任务列表的应用程序,我正在尝试将一些

控件添加到我可用于链接任务的表单中,我的初衷是< br $>
to: -


添加两个列表框,一个列表所有任务和另一个列表Linked

任务,我有两个按钮,在javascript中将项目从第一个

列表移动到第二个。

然后当用户点击thrid按钮时我想保存这些数据。


但是,第一个问题是事件验证器抛出了一个摇摆不定的

拒绝了我的回发。


我关闭了页面的EventValidation。


然后我注意到控制状态是与我在表格中加载

时相同。即使我改变了ListBox的内容?


希望这是有道理的,这是漫长的一天!


TIA < br $>

MC
I''m writing an app for managing Task Lists, I''m trying to add some
controls to a form that I can use to link tasks, my original intention was
to: -

Add two list boxes, one listing "all Tasks" and the other listing "Linked
Tasks", I have two buttons which in javascript move items from the first
list into the second.

Then when a user clicks a thrid button I would like to save this data.

however, the first problem was that the Event Validator threw a wobly and
rejected my postback.

I turned off EventValidation for the page.

I then noticed that the control state was the same as it was when I loaded
the form. even though I changed the contents of the ListBox?

Hope this makes sense, it''s been a long day!

TIA
MC



感谢Jim提供的信息。


你好MC,


对于你提到的两个问题,它们是由于以下原因:


1.默认情况下,ASP.NET Webcontrol的状态存储在ViewState中,它是一种压缩和编码的格式,无法在客户端使用
进行修改。因此,对webcontrol的状态进行任何更改(除了每次将回发的那些

属性,例如TextBox的文本或列表'

selectedItem )在客户端不会自动发布到服务器端。


2.对于EventValidation问题,这是由于新的事件验证

在ASP.NET 2.0中(默认启用),它将确保页面上的所有回发都由页面生成的内置回发脚本引发

或者任何webcontrol而不是其他自定义代码(直接注入脚本)。

例如,如果你使用Response.Write输出一些回发脚本,

它将违反事件验证。


对于这两个问题,您可以考虑以下方法来解决这些问题:


1)正如Jim建议的那样,你可以在页面和客户端使用html输入隐藏字段(< input

type =" hidden" ... />),每当

下拉列表已更改(添加或删除项目),您更新隐藏的

字段以便保留更改。页面回发后,您可以检查隐藏字段的值,并将状态同步到DropDownlist的

服务器控件实例中。


2)如果禁用EventValidation是可行的,你可以在这个

页面上关闭它。另外,由于EventValidation只是确保从控件self中真正提出了回发$ / b $ b,你可以使用脚本来调用某个控件'

回发事件。例如


我们可以使用脚本在客户端触发按钮的点击事件:


document.getElementById(" Button1" ;)。click();

你觉得怎么样?如果您有任何其他的考虑或想法,请感觉

免费在这里发布。


此致,


Steven Cheng


Microsoft MSDN在线支持主管


=================== ===============================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。

Thanks for Jim''s informative input.

Hi MC,

For the two issues you mentioned, they''re due to the following things:

1. The ASP.NET Webcontrol''s state is stored in ViewState by default and it
is a compressed and encoded format which can not be modified at
client-side. Thus, any change to the webcontrol''s state(except those
property that will be postback every time such as TextBox''s Text or List''s
selectedItem) at client-side will not be automatically post to server-side.

2. For the EventValidation problem, this is due to the new event validation
in ASP.NET 2.0(by default enabled), it will ensure that all the postback on
the page are raised by the built-in postback script generated by the page
or any webcontrol rather than other custom code(directly injected scripts).
For example, if you use Response.Write to output some postback scripts,
it will violate the event validation.

For the two issues, you can consider the following means to work them out:

1) As Jim suggested, you can use an html input hidden field(<input
type="hidden" .../>) in the page and at client-side, whenever the
dropdownlist has been changed(add or remove items), you update the hidden
field so as to persist the changes. After the page postback, you can check
the hidden field''s value and synchorize the status into DropDownlist''s
server control instance.

2) If disable EventValidation is doable, you can just turn off it on this
page. Else, since EventValidation just ensure the postback is really raised
from the control self, you can use script to invoke a certain control''s
postback event. e.g.

We can use script to trigger a button''s click event at client-side:

document.getElementById("Button1").click();
How do you think? If you have any other consideration or ideas, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


好的,我得到了隐藏字段的第一个解决方案,我实现了它

ok和我的代码很有效。


也许晚上已经太晚了但我有点困难

计算出EventValidiation的内容。


我宁愿不必为整个页面禁用事件验证。


你能解释一下吗?更多关于我需要什么来停止

发生eventValidation错误(没有关闭事件验证)?


我已经包裹了我的模块是一个网页控件,因为它会在别处使用,在我的应用程序中,这会帮助或阻碍这个问题吗?


TIA
< br $>
mc


Steven Cheng [MSFT]写道:
Ok, I get the first solution with the hidden field, I''ve implemented it
ok and my code works a treat.

Maybe it''s too late in the evening but I''m having a little difficulty
working out the EventValidiation stuff.

I''d rather not have to disable event validation for the whole page.

could you explain a little more about what would i need to to to stop
the eventValidation error occurring (without turning off event validation)?

I''ve wrapped my module is a web control as it will be used elsewhere, in
my app, will this help or hinder the problem?

TIA

mc

Steven Cheng[MSFT] wrote:

感谢Jim提供的信息输入。


你好MC,


这两个你提到的问题,它们归因于以下几点:


1.默认情况下,ASP.NET Webcontrol的状态存储在ViewState中它是

是一种压缩编码格式,无法在客户端的b / b
进行修改。因此,对webcontrol的状态进行任何更改(除了每次将回发的那些

属性,例如TextBox的文本或列表'

selectedItem )在客户端不会自动发布到服务器端。


2.对于EventValidation问题,这是由于新的事件验证

在ASP.NET 2.0中(默认启用),它将确保页面上的所有回发都由页面生成的内置回发脚本引发

或者任何webcontrol而不是其他自定义代码(直接注入脚本)。

例如,如果你使用Response.Write输出一些回发脚本,

它将违反事件验证。


对于这两个问题,您可以考虑以下方法来解决这些问题:


1)正如Jim建议的那样,你可以在页面和客户端使用html输入隐藏字段(< input

type =" hidden" ... />),每当
下拉列表已更改(添加或删除项目),您更新隐藏的

字段以便保留更改。页面回发后,您可以检查隐藏字段的值,并将状态同步到DropDownlist的

服务器控件实例中。


2)如果禁用EventValidation是可行的,你可以在这个

页面上关闭它。另外,由于EventValidation只是确保从控件self中真正提出了回发$ / b $ b,你可以使用脚本来调用某个控件'

回发事件。例如


我们可以使用脚本在客户端触发按钮的点击事件:


document.getElementById(" Button1" ;)。click();


您如何看待?如果您有任何其他的考虑或想法,请感觉

免费在这里发布。


此致,


Steven Cheng


Microsoft MSDN在线支持主管


=================== ===============================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。


Thanks for Jim''s informative input.

Hi MC,

For the two issues you mentioned, they''re due to the following things:

1. The ASP.NET Webcontrol''s state is stored in ViewState by default and it
is a compressed and encoded format which can not be modified at
client-side. Thus, any change to the webcontrol''s state(except those
property that will be postback every time such as TextBox''s Text or List''s
selectedItem) at client-side will not be automatically post to server-side.

2. For the EventValidation problem, this is due to the new event validation
in ASP.NET 2.0(by default enabled), it will ensure that all the postback on
the page are raised by the built-in postback script generated by the page
or any webcontrol rather than other custom code(directly injected scripts).
For example, if you use Response.Write to output some postback scripts,
it will violate the event validation.

For the two issues, you can consider the following means to work them out:

1) As Jim suggested, you can use an html input hidden field(<input
type="hidden" .../>) in the page and at client-side, whenever the
dropdownlist has been changed(add or remove items), you update the hidden
field so as to persist the changes. After the page postback, you can check
the hidden field''s value and synchorize the status into DropDownlist''s
server control instance.

2) If disable EventValidation is doable, you can just turn off it on this
page. Else, since EventValidation just ensure the postback is really raised
from the control self, you can use script to invoke a certain control''s
postback event. e.g.

We can use script to trigger a button''s click event at client-side:

document.getElementById("Button1").click();
How do you think? If you have any other consideration or ideas, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



这篇关于已在javascript中修改的控件的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆