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.

3
  • What you want is valid. Have you tried it? Commented Aug 7, 2013 at 12:32
  • Yes. But It was n't working. Commented Aug 7, 2013 at 12:36
  • Make sure Class1.ID is accessible and has a value within the scope of your RedirectTo function. Commented Aug 7, 2013 at 12:37

6 Answers 6

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;
        }
Sign up to request clarification or add additional context in comments.

Comments

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>

1 Comment

Might as well just embed the <%= ss %> within the string and skip the concatenation. And the URL is invalid.
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
        }
    }

Comments

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)%> ';

Comments

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"];
}

Comments

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;
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.