[英]Pass parameter as text to JavaScript function from .NET code-behind
基本上,我有一个从父窗口在新窗口中打开的gridview。 它有一堆记录,带有一个查看按钮,用于查看每个记录的详细信息(保留在同一新打开的窗口中)。 我在父窗口中有一个日历,该日历接受Date查询字符串参数以在页面加载时设置日历上的当前日期。 我只是想刷新父窗口中的日历,以匹配新打开的窗口中标签的日期。
下面的所有代码在新打开的窗口中。 下面的.Net代码是指单击该查看按钮并填充所有内容时的情况。 最后,我调用js刷新父窗口,并将LabelScheduleDate的值作为querystring参数传递。 现在,标签在后面的代码中以'03 / 25/2010'开头,但是当我将其传递给js时,在结尾的查询字符串中以'0.00005970149253731343'开头。 我不太确定是什么在改变价值,我想将其作为text传递。 我需要将其作为字符串对象传递吗? 我尝试过,但是我认为我做的不正确。
谢谢。
JavaScript功能
function RefreshParent(inputDate) {
window.opener.location = window.opener.location + "?Date=" + inputDate;
}
.NET代码隐藏
Protected Sub RadGridOnlineRequests_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridOnlineRequests.ItemCommand
If e.CommandName = "ViewOnlineRequest" Then
' populates LabelScheduleDate among other controls values
ScriptManager.RegisterStartupScript( _
Me, Me.GetType(), "clientScript", "RefreshParent(" & LabelScheduleDate.Text & ");", True)
End If
End Sub
您所要做的只是确保已渲染的脚本以文本两端的引号结尾:
RefreshParent('" & LabelScheduleDate.Text & "');
如果LabelScheduleDate.Text
的值为“ LabelScheduleDate.Text
”,则它将解析为
RefreshParent('03/25/2010');
...而您的代码将解析为
RefreshParent(03/25/2010);
...这意味着RefreshParent
收到3除以25除以2010。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.