Web表单上的两个Web用户控件实例出现问题 [英] Problem with two instances of web user control on a web form

查看:49
本文介绍了Web表单上的两个Web用户控件实例出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好
我有一个Web用户控件,其中包含一个html下拉列表和一个数据列表(在< div>内部).
在dropdownlist的单击上,div的可见属性已更改.为此,我将javascript代码用作:

Good Morning
I have a web user control which contain a html dropdownlist and a datalist(inside <div>).
on click of dropdownlist visible property of div is changed.for this i use javascript code as:

function Select1_onclick() {
       if (document.getElementById(''<%=Context.Items["id"] %>'').style.visibility != ''visible'') {
           document.getElementById(''<%=Context.Items["id"] %>'').style.visibility = ''visible'';
           document.getElementById(''<%=Context.Items["id"] %>'').style.display = ''block'';
       }
       else {
           document.getElementById(''<%=Context.Items["id"] %>'').style.visibility = ''hidden'';
           document.getElementById(''<%=Context.Items["id"] %>'').style.display = ''none'';
       }
   }



其中Context.Item ["id"]包含Webuser控件上的div的ID.
在我放置该Webuser控件的表单上.
我将Context.Item ["id"]初始化为:



where Context.Item["id"] contain id of div that is on webuser control.
on the form where i am placing that webuser control.
i initialise Context.Item["id"] as:

public void wucWithdraw_Init(object sender, EventArgs e)
   {
              Context.Items["id"] = "ctl00_ContentPlaceHolder1_wucWithdraw_DivDL" (where wucWithdraw is id of web user control)
   }


一切正常.
但是当我在页面上两次放置Web用户控件时,它仅保留Context.Item ["id"]的最后一个赋值.
请提供给我这样做的方法.
感谢


It is working fine .
but when i places web user control two times on page then it retain only the last assigned value of Context.Item["id"].
Please provide me the way to do that.
Thanks

推荐答案

Context.Items由两个控件共享.

您可以尝试,

Context.Items is shared by both the controls.

You can try like,

Context.Items[string.Format("{0}_id",wucWithdraw.ClientID)]



用于分配值. (即),使用与键一起附加的控件的ClientID来获取唯一值.

那么,这Context.Items的用途是什么?



for assigning values. (i.e), Use the ClientID of the Control appended along with the Key to get unique values.

So, What is this Context.Items for?


这篇关于Web表单上的两个Web用户控件实例出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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