Solved

C# request query string

Posted on 2011-02-28
8
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 45
c# DateTime Format validation 4 93
WPF and Powershell button hover change text 5 63
Easiest intro into .NET CORE? 2 33
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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