Reputation: 171
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.
Upvotes: 0
Views: 2626
Reputation: 12748
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;
}
Upvotes: 0
Reputation: 10198
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"];
}
Upvotes: 0
Reputation: 1976
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;
}
Upvotes: 1
Reputation: 20364
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)%> ';
Upvotes: 0
Reputation: 4489
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
}
}
Upvotes: 0
Reputation: 8726
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>
Upvotes: 0