有关用户控制的问题 [英] Question on user control

查看:86
本文介绍了有关用户控制的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在asp.net中有一个疑问,我创建了两个usercontrols.一个包含一个下拉列表,另一个包含标签.每当用户在第一个用户控制中更改该值时,该值就会显示在标签中.每当我更改该值时,页面就会打入服务器并附带结果.

我想每当更改dropdownlist中的值时,都应在标签中显示它.但该页面不会再次打入服务器.可能.如果有可能,请告诉我该怎么做.如果可以的话,请给我提供任何示例代码

问候,
Manikanta.

Hi,
I have a doubt in asp.net, I created two usercontrols. One contains a dropdownlist and another contain label. When ever the value changed in first user control that value displayed in the label. Every time when i changed the value the page hit the server and comes with the result.

I want whenever i change the value in dropdownlist it should be diplayed in the label. but the page dont hit the server again.possible. if it is possible tell me the way how it can be do it. give me any sample code if it is possible

regards,
Manikanta.

推荐答案

您可以使用javascript做到这一点.在设计视图中选择下拉菜单,然后将AutoPostback属性设置为false.下拉更改将不再导致回发到服务器.然后在下拉框上创建一个onChenge事件,并创建一个JavaScript处理程序,该处理程序在标签中显示选定的值.

祝你好运!
爱德华
You can do that using javascript. Select the dropdown in design view and set the AutoPostback property to false. The dropdown changes will not cause a postback to the server anymore. then create a onChenge event on your dropdown box and create a javascript handler which shows the selected value in the label.

Good luck!
Eduard


是的,做Autopostback = false;

调用JS函数onChange事件,该事件读取dropdown的值并填充在标签控件中.

可能是这样的.

yes, do Autopostback = false;

call the JS function onChange event, which reads the value of dropdown and populates in label control.

may be something like this.

function populateLabel()
{
    var ddCtrl = document.getElementById("DropDownCotrolClientId");
    var ddCtrlVal = e.options[e.selectedIndex].value;

    document.getElementById(''LabelCotrolClientId'').Value = ddCtrlVal;
}



这应该和上面一样简单...尝试一下.



This should be as simple as above... try it out..


这篇关于有关用户控制的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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