0

I want to redirect to another page and pass some parameters only using javascript. I am not supposed to use query string. Is there any way to achieve this? I am working on asp.net.

I want this redirection to use with devexpress scheduler control where when a user clicks on an appointment, the user be redirected to another page by passing the selected appointment's ID as parameter. It should not be passed as query string.

I would also like to know how to retrieve such kind of invisible parameter from the redirected page.

Ok I found out my solution.

I used javascript to click a <asp:Button> that is set to style="display:none". In my scenario, I could get the properties of scheduler appointment that I had clicked. I then put these properties in hidden fields and in the server side click event of this 'invisible' button, I use these hidden field values to make my redirection through server side. My code is as below

<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>
Nisha
  • 1,379
  • 16
  • 28

2 Answers2

3

Try this:

ASP.net Code:

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

Java Script Code:

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

jQuery Code:

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

jQuery Ajax Code:

$.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;
    }
});

// or short method is

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

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

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

Output:

?section=5&action=do
Nono
  • 6,986
  • 4
  • 39
  • 39
  • Your answer is quite good one but I am not allowed to use query string due to security reasons. – Nisha Jul 08 '13 at 06:57
  • @Nisha: Then try to manipulate with session in aspx. use session to pass param or you can use encrypt/decrypt with your secure data. Good Luck!! – Nono Jul 08 '13 at 07:27
1

try this document.location.href = "window-location.html"

already asked here

Community
  • 1
  • 1
Vinod Louis
  • 4,812
  • 1
  • 25
  • 46