客户端从asp.net下拉列表中处理selectedIndexChanged [英] client side handling of selectedIndexChanged from an asp.net dropdownlist

查看:91
本文介绍了客户端从asp.net下拉列表中处理selectedIndexChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的网站用户在下拉列表中更改了他们的选择,我想处理该客户端,并根据他们选择的内容填充一个带有不同文本的文本框。


我可以弄清楚如何做这个服务器端没问题,但我怎样才能在javascript中做到这一点。


我有类似的东西:

< asp:DropDownList ID =" StatusDropDownList" RUNAT = QUOT;服务器" >

< asp:ListItem Selected =" True"文本= QUOT;发行" Value =" Released">已发布< / asp:ListItem>

< asp:ListItem Text =" Down" Value =" Down" Down< / asp:ListItem>

< asp:ListItem Text =" Blocked" Value =" Blocked"> Blocked< / asp:ListItem>


< / asp:DropDownList>


我有一个文字我希望根据用户选择的内容填充框,我想在javascript中执行此操作...我似乎无法使该功能起作用。


有什么建议吗?

谢谢。

If the user of my site changes their selection in a dropdownlist, I would like to handle that client side and based on what they chose it would populate a text box with different text.

I can figure out how to do this server side no problem, but how do I get to do this in javascript.

I have something like:

<asp:DropDownList ID="StatusDropDownList" runat="server" >
<asp:ListItem Selected="True" Text="Released" Value="Released">Released</asp:ListItem>
<asp:ListItem Text="Down" Value="Down">Down</asp:ListItem>
<asp:ListItem Text="Blocked" Value="Blocked">Blocked</asp:ListItem>

</asp:DropDownList>

I have an text box that I want to populate based on what the user selects and I would like to do this in javascript...I cannot seem to get that function to work.

any suggestions?
thanks.

推荐答案


如果我的网站用户在下拉列表中更改了他们的选择,我想处理那个客户端,并根据他们选择的内容填充一个带有不同文本的文本框。


我可以弄清楚如何做这个服务器端没问题,但是如何在javascript中执行此操作。


我有类似的内容:


< asp:DropDownList ID =" StatusDropDownList" ; RUNAT = QUOT;服务器" >

< asp:ListItem Selected =" True"文本= QUOT;发行" Value =" Released">已发布< / asp:ListItem>

< asp:ListItem Text =" Down" Value =" Down" Down< / asp:ListItem>

< asp:ListItem Text =" Blocked" Value =" Blocked"> Blocked< / asp:ListItem>


< / asp:DropDownList>


我有一个文字我希望根据用户选择的内容填充框,我想在javascript中执行此操作...我似乎无法使该功能起作用。


有什么建议吗?

谢谢。
If the user of my site changes their selection in a dropdownlist, I would like to handle that client side and based on what they chose it would populate a text box with different text.

I can figure out how to do this server side no problem, but how do I get to do this in javascript.

I have something like:

<asp:DropDownList ID="StatusDropDownList" runat="server" >
<asp:ListItem Selected="True" Text="Released" Value="Released">Released</asp:ListItem>
<asp:ListItem Text="Down" Value="Down">Down</asp:ListItem>
<asp:ListItem Text="Blocked" Value="Blocked">Blocked</asp:ListItem>

</asp:DropDownList>

I have an text box that I want to populate based on what the user selects and I would like to do this in javascript...I cannot seem to get that function to work.

any suggestions?
thanks.



您确定要使用JavaScript代替服务器端代码来填充TextBox吗?


有一种方法使用JavaScript来做它但是使用服务器端代码会更容易....


你必须编写一个处理onblur事件的JavaScript DropDownList(HTML< select>列表),它获取所选值并设置TextBox的文本(设置< input type =" text">元素的" value"属性,即你的TextBox)


如果你真的想这样做......我会开始研究 w3c网站 ...它有很好的例子,我发现它是解决JavaScript问题的最佳资源。

另外,您可以查看有关如何检查文本的.NET文章框中包含一个数字,以获取如何在.NET中使用JavaScript的示例。


干杯!


-Frinny

Are you sure you want to use JavaScript instead of Server Side code to populate the TextBox?

There is a way to do it using JavaScript but it''d be easier to do with Server Side code....

You''d have to write a JavaScript that handles the onblur event for the DropDownList (which is an HTML <select> list) that takes the selected value and sets the TextBox''s text (set the "value" property of the <input type="text"> element that is your TextBox)

If you really want to do this....I''d start my research on the w3c website...it has good examples and I have found it to be the best resource for JavaScript problems.

Also, you could check out the .NET article on How to check if a textbox contains a number for an example of how to use JavaScript in .NET.

Cheers!

-Frinny


是的,我能够在服务器端使用C#,但是我必须单击提交按钮才能获得填充文本框的文本。我希望能够在下拉列表中选择不同的选项并让它填充文本框。 Mayb我做错了吗?就像这样...
Yeah, I was able to get it working with C# on server side, but I had to click the submit button to get the text to populate the text box. I wanted to just be able to select the different choice in the dropdownlist and have it populate the text box. Mayb I did it wrong? It was like this...
展开 | 选择 | Wrap | 行号


您不必使用提交按钮来执行此操作。

你需要做的就是设置DropDownList'的'autoPostBack" property to true ...这将导致DropDownList在所选索引发生更改时回发到服务器。


然后你编写的代码将TextBox中的文本更改为DropDownList在处理所选索引更改的方法中选择的值(或其他)。


但是这个解决方案仍然使用ServerSide代码来解决问题。

这些链接对你有帮助吗?


-Frinny

You shouldn''t have to use a submit button to do this.
All you need to do is set the DropDownList''s "autoPostBack" property to true...this will cause the DropDownList to postback to the server whenever the selected index changes.

Then you write the code that changes the text in your TextBox to be that of the DropDownList''s selected value (or whatever) in the method that handles the selected index change.

But this solution is still using ServerSide code to solve the solution.
Did those links help you at all?

-Frinny


是的,我是能够在服务器端使用C#,但我必须单击提交按钮以获取文本填充文本框。我希望能够在下拉列表中选择不同的选项并让它填充文本框。 Mayb我做错了吗?就像这样...
Yeah, I was able to get it working with C# on server side, but I had to click the submit button to get the text to populate the text box. I wanted to just be able to select the different choice in the dropdownlist and have it populate the text box. Mayb I did it wrong? It was like this...
展开 | 选择 | Wrap | 行号


这篇关于客户端从asp.net下拉列表中处理selectedIndexChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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