Solved

C# request query string

Posted on 2011-02-28
8
292 Views
Last Modified: 2012-05-11
I am requesting a a querystring from an asp page

<%varASP = "Some value"%>

	<script>
	function show()
	            {
	url = "http://usvawebapp/payroll2/dropdown/billing.aspx?value=<%varASP%>";
 
   
   window.location.href=url 
				} 
	</script>

Open in new window


Now i want use this value as a query string in a aspx page.  I can get the page to open fron asp.  I just don know how to use redirect.
protected void submit_Click(object sender, EventArgs e)
  {
     //tb1.Text = =<%varASP%>";

      details2.SelectCommand = "SELECT top 5 bachnumb, emp_id, patsno, SUM(hours * payrate) AS totalpay, SUM(hours * billrate) AS totalbill FROM GP_TimesheetLoad WHERE 1= " + tb1.Text +  " GROUP BY emp_id, patsno, bachnumb ";
      Response.Redirect("billing.aspx?id=" + tb1.Text);
      
      // details2.SelectCommand = Message1.Text;
      Message1.Text = "found";
      
      



  }

Open in new window

0
Comment
Question by:jaypappas
8 Comments
 
LVL 12

Expert Comment

by:HugoHiasl
ID: 35001892
Hmm.. what do you want to have as result?

What you are doing should work.

In the called page you can get the value with:

string id = Request.QueryString["id"]
0
 

Author Comment

by:jaypappas
ID: 35001939
its redirecting to http://usvawebapp/payroll2/dropdown/billing.aspx without the querystring.  It shoulb be
http://usvawebapp/payroll2/dropdown/billing.aspx?={some value}
0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35002632
You have to use  Response.Redirect("webpagename.aspx?Q_Name=" + some value

Please see below URL for more detail:

http://www.codeproject.com/KB/aspnet/QueryString.aspx
0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35004560
on asp page the url should be:-

url = "http://usvawebapp/payroll2/dropdown/billing.aspx?value=<%=varASP%>

Open in new window


you are missing the '=' operator inside <% %>
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jaypappas
ID: 35009002
@Mayank.  Thats fine I got that working thanks.

@ everybody-- But I am still having troubles I posted all the code.


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Register assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
      
       
      
      
  }


  protected void submit_Click(object sender, EventArgs e)
  {

       
      
      
      details2.SelectCommand = "SELECT top 5 bachnumb, emp_id, patsno, SUM(hours * payrate) AS totalpay, SUM(hours * billrate) AS totalbill FROM GP_TimesheetLoad WHERE 1= " + tb1.Text +  " GROUP BY emp_id, patsno, bachnumb ";
      Response.Redirect("billing.aspx?id=" + tb1.Text);
      
      Message1.Text= details2.SelectCommand ;
     
      
      



  }
</script>

    
    
</script>
<html xmlnsSQL Authentication</title>
    <style type="text/css">
body
{
background-color:white;
}
h1
{
background-color:#00ff00;
}
p
{
background-color:rgb(255,0,255);
}
</style>
<head>
     <form id="form1" runat="server" method="post">

<asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="wflow.gif"/>


     <asp:SqlDataSource ID="details2" runat="server" 
         ConnectionString="<%$ ConnectionStrings:details2 %>" 
         ProviderName="<%$ ConnectionStrings:details2.ProviderName %>" 
         SelectCommand="SELECT top 5 bachnumb, emp_id, patsno, SUM(hours * payrate) AS totalpay, SUM(hours * billrate) AS totalbill FROM GP_TimesheetLoad WHERE (1 = 1) AND (2 = 2) GROUP BY emp_id, patsno, bachnumb">
     </asp:SqlDataSource>


<asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False"
    DataSourceID="details2" EnableModelValidation="True">
    <Columns>
        <asp:BoundField DataField="bachnumb" HeaderText="bachnumb1"
            SortExpression="bachnumb" />
        <asp:BoundField DataField="emp_id" HeaderText="emp_id"
            SortExpression="emp_id" />
        <asp:BoundField DataField="patsno" HeaderText="patsno"
            SortExpression="patsno" />
        <asp:BoundField DataField="totalpay" HeaderText="totalpay"
            SortExpression="totalpay" ReadOnly="True" />
     <asp:BoundField DataField="totalbill" HeaderText="totalbill"
            SortExpression="totalbill" ReadOnly="True" />

    </Columns>
</asp:GridView>
<asp:TextBox id="tb1" runat="server" />

<asp:Button id = "submit" runat="server" onclick="submit_Click" text = "submit" />
<asp:label id="Message1" runat ="server"/><br />


</form>
</head>
<body/>
</html>

Open in new window

0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35009762
there is no issue with
Response.Redirect("billing.aspx?id=" + tb1.Text);

there is some issue with details2.SelectCommand
please debug and check each and every values.
0
 

Author Comment

by:jaypappas
ID: 35009926
I am trying to to debug the details2.slectcommand with the  
  Message1.Text= details2.SelectCommand ;

Open in new window

.  The message only shows up when I take out
 Response.Redirect("billing.aspx?id=" + tb1.Text);

Open in new window

0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35019061
Try to access the query string on Page_Load event not on submit_Click.

Your error:
You redirect to another page and try to reading the values on previous page. Its not possible.
You need to read the query string on new page.

If you redirect on same page, you have to read query string on Page_Load event.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now