列表框数据消失了 [英] Listbox data going away

查看:73
本文介绍了列表框数据消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net应用程序,用户当前在文本框中输入一个数字,

点击按钮并执行数据调用。她希望能够以多个数字(最多100个)输入



为了让事情看起来更好看,我创建了一个列表框

在文本框下面。她在文本框中输入数字,点击

我添加的另一个按钮,数字存储在列表框中。然后

我的计划是从列表框中获取所有这些数字,然后点击原始按钮进行数据通话。


这是我的问题。我使用java脚本填充列表框 -

防止每次用户点击我的添加

按钮时命中服务器。然而,列表框是服务器端lisbox。但是,当我点击原始按钮(即运行报告)时,数据在

列表框中消失。我试图使用EnableViewState属性,

不起作用。我已经尝试过使用AutoPostBack属性而且

不起作用。


我被告知问题是保留的唯一内容列表框

是选中的项目。所以我尝试编写一个javascript方法,当用户点击运行报告

按钮时,
会选择所有这些方法。它不起作用,因为我必须在我的代码中注册javascript

代码并在它执行之前清除该列表框

甚至一行代码代码隐藏。


我试图创建一个隐藏的文本框来存储数字和

这些都不起作用。我不能使用<输入带有一种隐藏的原因

这是一个客户端控件,我需要在服务器端使用这些数据。我想b $ b试图创建一个asp文本框并使其成为可见属性

false,但是我无法访问客户端的文本框当我想要填写它时,我想要填写它。


我想我已经辞职了使用多行文本框来让

用户一次性输入它们,但我讨厌这个想法,因为它导致用户走上了可能会犯很多错误的道路,因为他/她已经进入了b $ b 。我无法相信他们无法保留这些数据。

我缺少什么?

I have a .net app that a user currently enters a number in a text box,
hits a button and a data call is executed. She wants the ability to
enter in multiple numbers (up to 100).

So to make things look better visually for that, I created a listbox
under the text box. She enters the number in the text box, clicks
another button I added and the number is stored in the list box. Then
my plan was to grab all those numbers from the list box when she
clicks the original button to do the data call.

Here''s my problem. I filled the listbox using java script - to
prevent hitting the server every time the user clicks my "add"
button. The listbox however is a server side lisbox. But, the moment
I hit my original button (i.e."Run Report"), the data goes away in the
listbox. I have tried to use the EnableViewState property and that
doesn''t work. I''ve tried using the AutoPostBack property and that
doesn''t work.

I was told the issue is that the only thing retained in the list box
is the item selected. So I tried to write a javascript method that
would select all of them when the user clicks the "Run Report"
button. It doesn''t work, because I have to register the javascript
code in my code behind and it clears that listbox before it executes
even one line of code in the codebehind.

I tried to create a hidden text box to just store the numbers too and
that didn''t work. I can''t use a <inputwith a type of hidden cause
that is a client control and I need this data on the server side. I
tried to just create a asp text box and make it''s visible property
false, but then I can''t access the text box on the client side when I
want to fill it.

I think I''m resigned to using a multi-line textbox to just let the
user enter them in all at once, but I hate the idea because it leads
the user down a path of potentially making many mistakes as he/she
enters. I just can''t believe that their is no way to keep this data.
What am I missing?

推荐答案

"杜奇" < dn ****** @ dtgnet.com写在留言中

新闻:10 ************************ ********** @ k1g2000p rb.googlegroups.com ...
"Doogie" <dn******@dtgnet.comwrote in message
news:10**********************************@k1g2000p rb.googlegroups.com...

>我有一个用户当前输入的.NET应用程序在文本框中输入数字,

点击按钮并执行数据调用。她希望能够以多个数字(最多100个)输入

>I have a .NET app that a user currently enters a number in a text box,
hits a button and a data call is executed. She wants the ability to
enter in multiple numbers (up to 100).



OK。

OK.


为了让事情看起来更好看,我创建了一个列表框

在文本框下方。她在文本框中输入数字,点击

我添加的另一个按钮,数字存储在列表框中。然后

我的计划是从列表框中获取所有这些数字,当她点击原始按钮进行数据通话时。
So to make things look better visually for that, I created a listbox
under the text box. She enters the number in the text box, clicks
another button I added and the number is stored in the list box. Then
my plan was to grab all those numbers from the list box when she
clicks the original button to do the data call.



听起来很合理。

Sounds reasonable.


这是我的问题。我使用JavaScript填充列表框 -

防止每次用户点击我的添加

按钮时命中服务器。然而,列表框是服务器端lisbox。但是,当我点击原始按钮(即运行报告)时,数据在

列表框中消失。我试图使用EnableViewState属性,

不起作用。我尝试过使用AutoPostBack属性而且

不起作用。
Here''s my problem. I filled the listbox using JavaScript - to
prevent hitting the server every time the user clicks my "add"
button. The listbox however is a server side lisbox. But, the moment
I hit my original button (i.e."Run Report"), the data goes away in the
listbox. I have tried to use the EnableViewState property and that
doesn''t work. I''ve tried using the AutoPostBack property and that
doesn''t work.



这是ListBoxes的标准行为 - 对其元素所做的更改
通过客户端JavaScript收集的
不能在回发中存活。

That''s standard behaviour for ListBoxes - changes made to their elements
collection via client-side JavaScript do not survive a postback.


我被告知问题是列表框中保留的唯一内容

是选中的项目。所以我尝试编写一个JavaScript方法,当用户点击运行报告

按钮时,
会选择所有这些方法。它不起作用,因为我必须在我的代码中注册JavaScript

代码并在它执行之前清除该列表框

甚至一行代码代码隐藏。
I was told the issue is that the only thing retained in the list box
is the item selected. So I tried to write a JavaScript method that
would select all of them when the user clicks the "Run Report"
button. It doesn''t work, because I have to register the JavaScript
code in my code behind and it clears that listbox before it executes
even one line of code in the codebehind.



如果你的JavaScript应该选择ListBox中的所有元素

但事实上,清除ListBox,那么您的

JavaScript中的错误,或者它没有在页面循环中的正确位置运行。这个

需要在< asp:Button / control

的OnClientClick事件中运行才能进行回发。

If your JavaScript is supposed to select all of the elements in a ListBox
but, in fact, clears the ListBox, then there is either a bug in your
JavaScript, or it''s not running at the correct place in the page cycle. This
would need to run in the OnClientClick event of the <asp:Button /control
which does the postback.


我试图创建一个隐藏的文本框来存储数字和

这些都不起作用。
I tried to create a hidden text box to just store the numbers too and
that didn''t work.



你能更具体一点吗?

Can you be more specific?


我不能使用<输入类型隐藏原因是客户端控制

我需要在服务器端使用这些数据。
I can''t use a <inputwith a type of hidden cause that is a client control
and I need this data on the server side.



是的,你可以 - 只需给它一个runat =" server"标签......

Yes you can - just give it a runat="server" tag...


我试图创建一个asp文本框并使其可见属性

false,但后来我可以''当我想要填写它时,访问客户端的文本框。
I tried to just create a asp text box and make its visible property
false, but then I can''t access the text box on the client side when I
want to fill it.



那是因为将webcontrol的Visible属性设置为true阻止

控制从呈现到客户端浏览器。

That''s because setting a webcontrol''s Visible property to "true" prevents
that control from being rendered to the client browser.


我认为我已经辞职了使用多行文本框来让

的用户一次性输入它们,但我讨厌这个想法,因为它导致用户走上了可能会犯很多错误的路径,因为他/她

进入。我无法相信他们无法保存这些数据。

我缺少什么?
I think I''m resigned to using a multi-line textbox to just let the
user enter them in all at once, but I hate the idea because it leads
the user down a path of potentially making many mistakes as he/she
enters. I just can''t believe that their is no way to keep this data.
What am I missing?



一个隐藏的文本框绝对是这里的方式,所以我建议你的

JavaScript是问题所在。


请显示您的JavaScript以及如何调用它。

-

Mark Rae

ASP.NET MVP
http://www.markrae.net

A hidden textbox is definitely the way to go here, so I''d suggest that your
JavaScript is where the problem lies.

Please show your JavaScript and how you call it.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


11月7日,6:55 * am,Mark Rae [MVP]" < m ... @ markNOSPAMrae.netwrote:
On Nov 7, 6:55*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:

" Doogie" < dnlwh ... @ dtgnet.com写信息


新闻:10 *********************** *********** @ k1g2000p rb.googlegroups.com ...
"Doogie" <dnlwh...@dtgnet.comwrote in message

news:10**********************************@k1g2000p rb.googlegroups.com...

我有一个用户当前输入数字的.NET应用程序在文本框中,

点击按钮并执行数据调用。 *她希望能够以多个数字(最多100个)输入

I have a .NET app that a user currently enters a number in a text box,
hits a button and a data call is executed. *She wants the ability to
enter in multiple numbers (up to 100).



好​​的。


OK.


为了让事情看起来更好看,我创建了一个列表框

在文本框下方。 *她在文本框中输入数字,点击

我添加的另一个按钮,数字存储在列表框中。 *然后

我的计划是当她点击原始按钮进行数据通话时,从列表框中获取所有这些数字。
So to make things look better visually for that, I created a listbox
under the text box. *She enters the number in the text box, clicks
another button I added and the number is stored in the list box. *Then
my plan was to grab all those numbers from the list box when she
clicks the original button to do the data call.



听起来很合理。


Sounds reasonable.


这是我的问题。 *我使用JavaScript填充列表框 -

防止每次用户点击我的添加

按钮时命中服务器。 *但是列表框是服务器端的lisbox。 *但是,那一刻

我点击原来的按钮(即运行报告),数据会在

列表框中消失。 *我试图使用EnableViewState属性,

不起作用。 *我尝试过使用AutoPostBack属性而且

不起作用。
Here''s my problem. *I filled the listbox using JavaScript - to
prevent hitting the server every time the user clicks my "add"
button. *The listbox however is a server side lisbox. *But, the moment
I hit my original button (i.e."Run Report"), the data goes away in the
listbox. *I have tried to use the EnableViewState property and that
doesn''t work. *I''ve tried using the AutoPostBack property and that
doesn''t work.



这是ListBoxes的标准行为 - 对其元素所做的更改
通过客户端JavaScript收集的
不能在回发中存活。


That''s standard behaviour for ListBoxes - changes made to their elements
collection via client-side JavaScript do not survive a postback.


我被告知问题是列表框中保留的唯一内容

是选中的项目。 *所以我尝试编写一个JavaScript方法,当用户点击运行报告

按钮时,
会选择所有这些方法。 *它不起作用,因为我必须在我的代码中注册JavaScript

代码并在它执行之前清除该列表框

甚至一行代码代码隐藏。
I was told the issue is that the only thing retained in the list box
is the item selected. *So I tried to write a JavaScript method that
would select all of them when the user clicks the "Run Report"
button. *It doesn''t work, because I have to register the JavaScript
code in my code behind and it clears that listbox before it executes
even one line of code in the codebehind.



如果你的JavaScript应该选择ListBox中的所有元素

但事实上,清除ListBox,那么您的

JavaScript中的错误,或者它没有在页面循环中的正确位置运行。这个

需要在< asp:Button / control

的OnClientClick事件中运行才能进行回发。


If your JavaScript is supposed to select all of the elements in a ListBox
but, in fact, clears the ListBox, then there is either a bug in your
JavaScript, or it''s not running at the correct place in the page cycle. This
would need to run in the OnClientClick event of the <asp:Button /control
which does the postback.


我试图创建一个隐藏的文本框来存储数字和

这些都不起作用。
I tried to create a hidden text box to just store the numbers too and
that didn''t work.



你能更具体一点吗?


Can you be more specific?


我不能使用<输入类型隐藏原因是客户端控制

我需要在服务器端使用这些数据。
I can''t use a <inputwith a type of hidden cause that is a client control
and I need this data on the server side.



是的,你可以 - 只需给它一个runat =" server"标签......


Yes you can - just give it a runat="server" tag...


我试图创建一个asp文本框并使其可见属性

false,但后来我可以''当我想要填写它时,访问客户端的文本框。
I tried to just create a asp text box and make its visible property
false, but then I can''t access the text box on the client side when I
want to fill it.



这是因为将webcontrol的Visible属性设置为true阻止

控制从呈现到客户端浏览器。


That''s because setting a webcontrol''s Visible property to "true" prevents
that control from being rendered to the client browser.


我认为我已经辞职了使用多行文本框来让

的用户一次性输入它们,但我讨厌这个想法,因为它导致用户走上了可能会犯很多错误的路径,因为他/她

进入。 *我无法相信他们无法保存这些数据。

我缺少什么?
I think I''m resigned to using a multi-line textbox to just let the
user enter them in all at once, but I hate the idea because it leads
the user down a path of potentially making many mistakes as he/she
enters. *I just can''t believe that their is no way to keep this data.
What am I missing?



一个隐藏的文本框绝对是这里的方式,所以我建议你的

JavaScript是问题所在。


请显示您的JavaScript以及如何调用它。


-

Mark Rae

ASP.NET MVPhttp://www.markrae.net


A hidden textbox is definitely the way to go here, so I''d suggest that your
JavaScript is where the problem lies.

Please show your JavaScript and how you call it.

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net



使用runat =" server"对于输入框做了伎俩。我不知道

你可以得到一个输入框在服务器上运行。非常感谢你!我以b / b
的方式再次进行网络开发,所以我好像忘记了我学到的东西!


但是对于这个评论:

Using runat="server" for the input box did the trick. I was unaware
you could get an input box to run at server. Thank you very much! I
do web development in an on again/ off again type manner so I seem to
forget as much as I learn!

For this comment though:


如果你的JavaScript应该选择ListBox中的所有元素

但事实上,清除ListBox,然后你的

JavaScript中有一个错误,或者它没有在页面循环中的正确位置运行。这个

需要在< asp:Button / control

的OnClientClick事件中运行才能进行回发。
If your JavaScript is supposed to select all of the elements in a ListBox
but, in fact, clears the ListBox, then there is either a bug in your
JavaScript, or it''s not running at the correct place in the page cycle. This
would need to run in the OnClientClick event of the <asp:Button /control
which does the postback.



我的代码中没有任何内容清除列表框。我已经通过我的所有代码放置了断点

,并且在执行一行代码

之前清除了列表框。关于.NET的东西正在清除那个列表框。所以我

甚至无法让我的代码执行,因为当它尝试时,

列表框已被清除。这让我很困惑。我不确定

我理解价值观会消失的目的。


但它现在可以使用隐藏文本框选项。所以我很高兴。

再次感谢!

Nothing in my code is clearing the list box. I have put breakpoints
through all my code and the listbox is cleared before ONE line of code
is executed. Something about .NET is clearing that listbox. So I
couldn''t even get my code to execute because by the time it tried, the
list box was already cleared. This is perplexing to me. I''m not sure
I understand the purpose of values going away like that.

But it works now with the hidden text box option. So I''m happy.
Thanks again!


可能是你误解了这个建议。
May be you misunderstood the advice.

我被告知问题是列表框中保留的唯一内容

是选中的项目。所以我试着写一个javascript方法,
I was told the issue is that the only thing retained in the list box
is the item selected. So I tried to write a javascript method that



你被告知是对的。

You were told the right thing.


会选择所有这些都是当用户点击运行报告

按钮时。它不起作用,因为我必须在我的代码中注册javascript

代码并在它执行之前清除该列表框

甚至一行代码代码隐藏。
would select all of them when the user clicks the "Run Report"
button. It doesn''t work, because I have to register the javascript
code in my code behind and it clears that listbox before it executes
even one line of code in the codebehind.



首先,不需要在后面的代码中编写javascript。

您可以使用脚本标记直接在aspx页面上编写。


一旦你使用javascript填充列表框(即< selecttag)并选择

所有这些(确保列表框是多选的),你可以提交

it。


但请记住,您永远无法通过列表框访问提交的代码。

您需要从回发中访问它们数据。使用Request.Forms [" Listbox.UniqueID"]获得的数据可以是
。这绝对是

将包含所有选项。

Listbox是最好的选择,当然,除非你使用ajax创建自己的自定义

控件支持。


-

Vinay Khaitan

[Windows窗体布局控制]
http://www.smart-components.com/

--- -------------------------------------------------- -----------

First of all, there is no need to write javascript in code behind.
You can write directly on aspx page with script tag.

Once you populate listbox (i.e. <selecttag) using javascript and select
all of them (make sure that listbox is multi-selectable), you can submit
it.

But remember, you can never access submitted code via listbox.
You need to access them from postback data. That data can be
got using Request.Forms["Listbox.UniqueID"] . This definitely
would contain all of the options.
Listbox is the best option, surely, unless you create your own custom
control with ajax support.

--
Vinay Khaitan
[Windows Forms Layout Control]
http://www.smart-components.com/
----------------------------------------------------------------


这篇关于列表框数据消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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