从另一个页面 C# 触发页面的方法
本文关键字:方法 另一个 | 更新日期: 2023-09-27 18:36:44
伙计们,我在弹出窗口上有一个日历。我需要在其上选择的日期进入打开弹出窗口的页面的文本框(即在弹出窗口的父页面中)。
我已经设置了公共访问方法,该方法将在弹出窗口中选择的日期作为首次注册指令
<%@ PreviousPageType VirtualPath="~/DateFrom.aspx" %>
然后在弹出窗口中
//making value of hidden field available to the "destination page"
public string from
{
get
{
return hdnFrom.Value.ToString();
}
}
我还可以通过一种方法在父页面上访问此值,例如
public string display()
{
Label1.Text = PreviousPage.from;
}
但是我需要在弹出窗口中选择日期后立即显示日期。
如何从弹出窗口触发display()
?
另一种方法,与Saghir的方法相比,有点像反向方法。
您让父页面打开弹出页面,如下所示:
function openCalendar(){
window.open('calendar.aspx', '_blank', 'width=200,height=100');
}
function populateCalendarTextbox(val){
document.getElementById('calendarbox').value = val;
}
在弹出页面(日历.aspx)中,您编写如下代码:
function sendToParent(value){
//Assume value is assigned from the calendar control
//by passing as argument to this function
window.opener.populateCalendarTextbox(value);
window.close();
}
您可以使用 javascript 将值从子弹出窗口发送到父网页这是您的child.aspx
脚本
<script type = "text/javascript">
function childFunc()
{
return document.getElementById ("<%Calender1.ClientID%>").value;
}
</script>
在你的parent.aspx
<script type = "text/javascript">
var PopUpObj;
function popUp(url)
{ PopUpObj = window.open(url); PopUpObj.focus(); }
function callChildFunc()
{
if(popUpObj != null && !popUpObj.closed)
{
var val = popUpObj.childFunc();
alert(val);
}
}
</script>
希望这会有所帮助