Solved

C# request query string

Posted on 2011-02-28
8
295 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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