dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersRavindran
Ajatshatru Upadhyay
abhishek
More...




Forums » .NET » ASP.NET »

Query string


Posted Date: 08 Aug 2008      Posted By:: K.ChandraShekar Reddy     Member Level: Gold    Member Rank: 755     Points: 1   Responses: 6



How to use query string to pass values between two pages.




Responses

#278872    Author:       Member Level: Diamond      Member Rank: 1     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 3

hello,
u can pass the value through Query String from one page to another.

here is the example

Response.Redirect("managearticles.aspx?Mode=Edit&" + "ArticleID=" + intID + "&IssueID=" + lintIssueId + "&pi=1");

thanks
Anil pandey

Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



#278876    Author:       Member Level: Gold      Member Rank: 0     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 6

hi,

here we r trying to pass url between two pages using get method .

refer this code you can get some idea abt ur code.

1. How do I append stuff to the URL?
There are more than one ways to append "stuff" to the URL. The method depends on the way you want variables to be passed.

If the next page is accessed through a link, then the <a> tag can be used alone.
<a href="redirect.html?page=1">Page 1</a>
<a href="redirect.html?page=2">Page 2</a>
<a href="redirect.html?page=3">Page 3</a>
etc.

The other way is through form values. For your form tag:
<form name="tform" action="redirect.html" method="get">
<select name="page">
<option value="1" selected="selected">Page 1</option>
<option value="2">Page 2</option>
<option value="3">Page 3</option>
</select><br>
<input type="submit" value="Go!">
</form>

For this tutorial, I will use a simple name page, one with a field to enter the name, another with a page to display it. However, this method will work for as many variables as necessary, as long as the maximum length of the URL is not passed.


<!-- entername.html (pseudocode) -->
<html>
<head>
<!-- head stuff here -->
</head>
<body>
<form name="theform" action="showname.html" method="get">
<input type="text" name="name"><br>
<input type="submit" value="Show">
</form
</body>
</html>


The above is a simple page that allows a user to enter their name.

2. How do I retrieve the values from the URL?
Here is showname.html.


<html>
<head>
<!-- head stuff -->
<script type="text/javascript">
<!-- hide from old browsers

function getValue(varname)
{
// First, we load the URL into a variable
var url = window.location.href;

// Next, split the url by the ?
var qparts = url.split("?");

// Check that there is a querystring, return "" if not
if (qparts.length == 0)
{
return "";
}

// Then find the querystring, everything after the ?
var query = qparts[1];

// Split the query string into variables (separates by &s)
var vars = query.split("&");

// Initialize the value with "" as default
var value = "";

// Iterate through vars, checking each one for varname
for (i=0;i<vars.length;i++)
{
// Split the variable by =, which splits name and value
var parts = vars[i].split("=");

// Check if the correct variable
if (parts[0] == varname)
{
// Load value into variable
value = parts[1];

// End the loop
break;
}
}

// Convert escape code
value = unescape(value);

// Convert "+"s to " "s
value.replace(/\+/g," ");

// Return the value
return value;
}

// end hide -->
</script>
</head>
<body>
<h1>Hello,
<script type="text/javascript">
<!-- hide
var name = getValue("name");
document.write(name);
// end hide -->
</script>
</h1>
</body>
</html>



#278882    Author:       Member Level: Silver      Member Rank: 0     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 3

hi,
refer this code
Response.Redirect("Webform2.aspx?Name=" +
this.txtName.Text + "&LastName=" +
this.txtLastName.Text);

this.txtBox1.Text = Request.QueryString["Name"];
this.txtBox2.Text = Request.QueryString["LastName"];






#278920    Author:       Member Level: Gold      Member Rank: 12     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 4

Hi,

in first page we need to add the query string in the url where we need to post to the next page like this.

Resposeredirect("nextpage.aspx?name=jk&id=10")

in next page we can get ths values like this

dim strname as string =Request.Querystring("name")
dim strid as string =Request.Querystring("id")

Regards
JK

Thanks & Regards
D.Jeya Kumar(JK)



#278937    Author:       Member Level: Gold      Member Rank: 402     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 4

To Pass values from one web form to another web form named as Webform2.aspx :

Response.Redirect("Webform2.aspx?Name=" + this.txtName.Text + "&PhoneNo=" +
this.txtPhoneNo.Text);

Getting the values from the Query String in Webform2.aspx :

this.Name.Text = Request.QueryString["Name"];
this.PhoneNo.Text = Request.QueryString["PhoneNo"];



#311485    Author:       Member Level: Bronze      Member Rank: 0     Date: 29/Oct/2008   Rating: 2 out of 52 out of 5     Points: 5

Query string :
It will arrange data with in HTTP header by appending to the Url in the form of query string, the data will be visible to the user, it doest provide security for the sensitive data and transmission will be faster.

LOGIN.HTML
<HTML>
<BODY>
<FORM METHOD="POST" ACTION =<"LOGIN.ASP">
USERNAME:<INPUT NAME="T1"> <BR>
PASSWORD:<INPUT TYPE="PASSWORD" NAME="T2"><BR>
</FORM>
</BODY>
</HTML>

lOGIN.ASP
<% UNAME=REQUEST.FORM ("T1")
RESPONSE.WRITE("<H2> WELCOME <BR> TO <BR> &"UNAME &"</H2>")%>




Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : datagrid..refresh ta current record..
Previous : regarding datareader in ado.net
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages

My Profile

Active Members
TodayLast 7 Daysmore...


Awards & Gifts


Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.