Solved

C# request query string

Posted on 2011-02-28
8
294 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

9 Experts available now in Live!

Get 1:1 Help Now