Solved

C# request query string

Posted on 2011-02-28
8
293 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COnsume rest client 6 36
Wav problem 4 19
Video Player 2017 5 17
How useful is the free version of Selenium? 3 16
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

27 Experts available now in Live!

Get 1:1 Help Now