2013-07-08 29 views
0

我想重定向到另一个页面,并只传递一些参数,只使用javascript。我不应该使用查询字符串。有什么办法可以做到这一点?我在asp.net上工作。重定向到另一个页面,使用JavaScript,无查询字符串

我想要这个重定向与devexpress调度程序控制一起使用,当用户点击一个约会时,通过传递所选约会的ID作为参数,用户被重定向到另一个页面。它不应该作为查询字符串传递。

我也想知道如何从重定向页面检索这种不可见的参数。

好的,我找到了我的解决方案。

我用javascript来点击设置为style="display:none"的。在我的场景中,我可以获取我点击过的调度程序预约的属性。然后我将这些属性放在隐藏字段中,并在服务器端单击这个“隐形”按钮事件,我使用这些隐藏的字段值通过服务器端进行重定向。我的代码如下

<asp:Button ID="Appointment" runat="server" Text="sample" 
    onclick="Appointment_Click" style="display:none"/> 
<asp:HiddenField ID="hfID" runat="server" /> 
<asp:HiddenField ID="hfSubject" runat="server" /> 
<asp:HiddenField ID="hfDate" runat="server" /> 

<script type="text/javascript" language="javascript"> 
    function OnAppointmentClick(s, e) { 
     //debugger; 
     var apt = scheduler.GetAppointmentById(e.appointmentId); 

     var apt1 = scheduler.GetAppointmentProperties(e.appointmentId); 

     var aptID = document.getElementById('<%= hfID.ClientID %>'); 
     var aptDate = document.getElementById('<%= hfDate.ClientID %>'); 
     var aptSubject = document.getElementById('<%= hfSubject.ClientID %>'); 
     aptID.value = e.appointmentId; 
     var date = (apt.startDate.getMonth()+1) + '/' + apt.startDate.getDate() + '/' + apt.startDate.getYear(); 
     aptDate.value = date; 
     aptSubject.value = apt.CODE; 
     document.getElementById('<%= Appointment.ClientID %>').click(); 
    }  
    </script> 
+0

这是你的功课? :) – Safeer

+0

不,这是我的办公室工作。我正在使用devexpress调度程序。 – Nisha

回答

2

试试这个:

ASP.net代码:

Response.Headers.Add("id", "testtest"); 
Response.Redirect("http://www.somesite.com/somepage.aspx"); 

Java脚本代码:

window.location = 'http://www.somesite.com/somepage.aspx?q=manvswild'; 

jQuery代码:

var url = "http://www.somesite.com/somepage.aspx?q=manvswild"; 
$(location).attr('href',url); 

jQuery的Ajax代码:

$.ajax({ 
    type : 'POST', 
    url : 'page.aspx', 
    data : { 
     paramname1 : "put_param_value_here", 
     paramname2 : "put_param_value_here", 
     paramname3 : "put_param_value_here" 
    }, 
    dataType : 'html', 
    success : function (e) { 
     window.location = e; 
    } 
}); 

//或短的方法是

$.post("page.aspx", { 
    param1 : 'one', 
    param2 : 'two' 
}, function (data) { 
    window.location = data; 
}); 

jQuery插件:http://plugins.jquery.com/project/query-object

alert($.query.set("section", 5).set("action", "do").toString()); 

输出:

?section=5&action=do 
+0

您的答案相当不错,但由于安全原因,我不允许使用查询字符串。 – Nisha

+0

@Nisha:然后尝试在aspx中使用会话进行操作。使用会话传递参数或者您可以使用加密/解密与您的安全数据。祝你好运!! –

1

试试这个 document.location.href = “窗口location.html”

已经问here

+0

对不起,但你提供的链接不会谈论传递参数。 – Nisha

相关问题