0

I want to pass a class variable from 1 page to another page on link button click. The link button click event is written in the javascript query as follows:

<script type="text/javascript">
        function RedirectTo() {
            window.location.href = 'ApplyJobsByCandidate.aspx';
            return false;
        }

Now how can i pass a class variable through the query string? I want something like 'ApplyJobsByCandidate.aspx?id='+Class1.ID;

Please help me.

Tannya
  • 161
  • 6
  • 21

6 Answers6

1

You can pass in the value into the function, then access add it into the query string

<script type="text/javascript">
        function RedirectTo(id) {
            window.location.href = 'ApplyJobsByCandidate.aspx?id=' + id;
            return false;
        }
Dan Drews
  • 1,966
  • 17
  • 38
0

in code behind

    public string ss
    {
        get
        {
            return ViewState["ss"].ToString();
        }
        set
        {
            ViewState["ss"] = value;
        }
    }

in some mothod set ss value like

ss = Class1.ID

in javascript

  <script type="text/javascript">
    function RedirectTo() {
        window.location.href = 'ApplyJobsByCandidate.id=' + '<%= ss %>';
        return false;
    }
</script>
sangram parmar
  • 8,462
  • 2
  • 23
  • 47
0

Try

<script type="text/javascript">
    function RedirectTo() {
        window.location.href = 'ApplyJobsByCandidate.aspx?Id=' +Id;
        return false;
    }
</script>

In C# Code

   if (Request.QueryString["id"] != null) {
        try
        {
            id = int.Parse(Request.QueryString["id"]);
        }
        catch
        {
            // deal with it
        }
    }
Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49
0

If you have a public static property within a class, then you can access it like so;

window.location.href = '<%=string.format("ApplyJobsByCandidate.aspx?id={0}", MyClass.id)%> ';
Tim B James
  • 20,084
  • 4
  • 73
  • 103
0

Another way to set class value into hidden field and send that value

Js code:

var getValue= $("#hiddenField1").val();
window.location.href = 'ApplyJobsByCandidate.aspx?id=' + getValue;

Code behind: On ApplyJobsByCandidate.aspx.cs

if(Request.QueryString["id"] != null)
{
string fetch_id = Request.QueryString["id"];
}
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
0

If you have access to the class in your page, you can do.

<script type="text/javascript">
        function RedirectTo() {
            window.location.href = 'ApplyJobsByCandidate.aspx?id=<% =Class1.ID %>';
            return false;
        }
the_lotus
  • 12,668
  • 3
  • 36
  • 53