Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javascript检索查询字符串_Javascript_C#_Asp.net - Fatal编程技术网

从javascript检索查询字符串

从javascript检索查询字符串,javascript,c#,asp.net,Javascript,C#,Asp.net,谁来帮帮我。。我曾经研究过如何使用java脚本检索查询字符串,但似乎没有成功。当用户单击放置在网格视图中的按钮时,我需要打开窗体(不同的web窗体)的窗口打印视图。网格视图中的每一行都有自己的打印按钮,因为它有不同的id,因为表单数据是从id中检索的(数据库中的主键是指trip id)。下面是我的java脚本代码。打印窗口可以打开,但表单数据无法检索 <script type="text/javascript"> function printExternal() { v

谁来帮帮我。。我曾经研究过如何使用java脚本检索查询字符串,但似乎没有成功。当用户单击放置在网格视图中的按钮时,我需要打开窗体(不同的web窗体)的窗口打印视图。网格视图中的每一行都有自己的打印按钮,因为它有不同的id,因为表单数据是从id中检索的(数据库中的主键是指trip id)。下面是我的java脚本代码。打印窗口可以打开,但表单数据无法检索

 <script type="text/javascript">
   function printExternal() {
   var data='<%=this.Request.QueryString["tripid"]%>';
   var printWindow = window.open('PrintBusinessTrip.aspx?tripid=' + data, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
   printWindow.addEventListener('load', function () {
   printWindow.print();
   printWindow.close();
   }, true);
   }
 </script>
我真的非常感谢任何帮助。因为我对java脚本和asp.net还不熟悉。对不起,我的英语不好


问题出在
printExternal
Javascript函数中。您不应该使用查询字符串获取
tripid
,因为它不会为表中的每一行更改

相反,您可以从每个按钮将
tripid
作为
printExternal
函数的参数传递

<asp:Button ID="sendbtn" runat="server" OnClientClick='<%# Eval("tripid", "printExternal({0})") %>' Text="Print" />

在我的新WebForm项目中,您的代码可能存在重复。请发布不起作用的完整代码。事实上,代码运行良好,但输出没有显示我想要的内容。我已经为打印视图添加了图像,您可以从url中看到,没有读取查询字符串id。我的javascript代码正确吗至于检索查询字符串?我可以问一个问题吗?如果你能帮忙的话。为什么打印窗口不能在IE上工作。但是对于Chrome和Firefox来说很好。是因为我使用了add Eventlistener吗?
   var printWindow = window.open('PrintBusinessTrip.aspx?tripid=102' + data, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
<asp:Button ID="sendbtn" runat="server" OnClientClick='<%# Eval("tripid", "printExternal({0})") %>' Text="Print" />
<button type="button" onclick="printExternal(<%# Eval("tripid") %>);">Print</button>
function printExternal(tripid) {
    var printWindow = window.open('PrintBusinessTrip.aspx?tripid=' + tripid, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
    printWindow.addEventListener('load', function () {
        printWindow.print();
        printWindow.close();
    }, true);
}