在asp.net中隐藏取消隐藏的一组文本框 [英] hide unhide set of textboxes in asp.net

查看:116
本文介绍了在asp.net中隐藏取消隐藏的一组文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网页表单上隐藏一组textboxex,具体取决于下拉列表中的值基础。如果下拉列表值已更改,我必须根据我的要求隐藏取消隐藏文本框。我在页面中使用表格,一些文本框对所有人来说都是常见的,我不需要隐藏它们。现在我给每个人提供id并将其隐藏在代码后面。也可以通过从自动完成文本框中选择值来填充这些文本框中的值。但是我面临一些问题和他们在一起怎么办呢?

请帮助..

I want to hide a set of textboxex on a web form depending on the basis of value in a dropdownlist.If dropdownlist value is changed i have to hide unhide textboxes depending on my requirement.I m using a table in my page,some textboxes are common for all,i dont need to hide them.Right now i am giving id to each and hiding them from code behind.Also i m filling values in these textboxes by selecting values from an autocomplete textbox.But i am facing some issues with them.how can i do this in a proper way ?
Please help..

推荐答案

您可以通过以下方式迭代控件并隐藏 -

You can iterate through controls and hide in the following way -
foreach(Control ctl in Page.Controls)
{
 ctrlType= Convert.ToString(ctrl.GetType());
 if(ctrlType== "System.Web.UI.WebControls.TextBox")
 {
  ((TextBox)ctl).Visible = false;
 }
}


您也可以非常轻松地在客户端执行此操作。仅当您需要来自服务器的某些数据时才发布,否则隐藏/显示应该在客户端完成。为您需要隐藏/显示的所有文本框分配一个公共类。在更改下拉列表时,编写一个JavaScript函数,在该函数中按类名选择元素并将其显示样式设置为none / block。如果使用jQuery,语法会更容易。试着告诉我们它是怎么回事。
You can do this on client side very easily as well. Post only if you need some data from Server otherwise hide/show should be done on client side. Assign a common class to all those textboxes you need to hide/show. On change of dropdown, write a JavaScript function in which you select elements by class name and set their display style to none/block. The syntax will be very much easier if you are using jQuery. Try and let us know how it goes.


<table id="tablehide"  runat="server">

<tr id="trhide"  runat="server">
<td id="tdhide"  runat="server">

</td>

</tr>

</table>







Codebehind:

tablehide.visible=false;
(or)
trhide.visible=false;
(or)
tdhide.visible=false;







tablehide.visible=true;
(or)
trhide.visible=true;
(or)
tdhide.visible=true;







将您的用户控件放在表格中并隐藏所有内容。




place your usercontrol with in the table and hide the whole things.


这篇关于在asp.net中隐藏取消隐藏的一组文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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