所以,用户控件的事件中,无法捕获主页面上的控件(如:<asp:textbox id="txtBillNo"/>,原因是它还未被解析)。
用如下方法可以解决这个问题:
在用户控件的"新增"事件中注册一个隐藏控件:
private
void
imgbtnAdd_Click(
object
sender, System.Web.UI.ImageClickEventArgs e)
{
this .Page.RegisterHiddenField( " IsOpenAddPage " , " true " );
}
{
this .Page.RegisterHiddenField( " IsOpenAddPage " , " true " );
}
然后在主页面的最底下写:
</
tr
>
</ table >
</ FORM >
< script language ="javascript" >
var obj = document.getElementById( " IsOpenAddPage " );
if (obj != null )
{
if (obj.value == ' true ')
{
OpenAddPage();
obj.value = '';
}
}
function OpenAddPage()
{
var SID = document.getElementById('txtBillNo').value;
var url = '.. / CangKuLL / CangKuLLAdd.aspx ? returncontrol = CCDataGrid1_imgbtnAdd & strBillNo = ' + SID;
window.open(url,'new_1','left = 160 ,top = 200 ,height = 450 ,width = 750 ,toolbar = 0 ,scrollbars = 2 ');
}
</ script >
</ BODY >
</ HTML >
</ table >
</ FORM >
< script language ="javascript" >
var obj = document.getElementById( " IsOpenAddPage " );
if (obj != null )
{
if (obj.value == ' true ')
{
OpenAddPage();
obj.value = '';
}
}
function OpenAddPage()
{
var SID = document.getElementById('txtBillNo').value;
var url = '.. / CangKuLL / CangKuLLAdd.aspx ? returncontrol = CCDataGrid1_imgbtnAdd & strBillNo = ' + SID;
window.open(url,'new_1','left = 160 ,top = 200 ,height = 450 ,width = 750 ,toolbar = 0 ,scrollbars = 2 ');
}
</ script >
</ BODY >
</ HTML >
这样,在用户控件的"新增"事件中,就可以访问主页面上的控件了!
(用户控件的"新增"事件会刷新主页面,所以会重新执行上面这段脚本)