Passing a variable to another page

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 1
Reputation: Dano56 is an unknown quantity at this point 
Solved Threads: 0
Dano56 Dano56 is offline Offline
Newbie Poster

Passing a variable to another page

 
0
  #1
Feb 15th, 2008
I need help getting a variable from one page displayed onto another. I have two pages, mainmenu.aspx and secondmenu.aspx. mainmenu.aspx contains Textbox1 which contains some user-entered number in it. When the user clicks on Button1 on mainmenu.aspx, I need the table, Table1, on secondmenu.aspx to reflect that new selection.

Thanks for any help or ideas.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: bbqchickenrobot is an unknown quantity at this point 
Solved Threads: 2
bbqchickenrobot bbqchickenrobot is offline Offline
Light Poster

Re: Passing a variable to another page

 
0
  #2
Feb 16th, 2008
First off- what language are you using vb.net or c#? You should verify the user entry is a # if that's what is expected... then convert it to a number vb = CInt/Int3.Parse(varNumber) then "post" this page to your 2nd page secondmemu.aspx - then do a request.form() for the textfield posted from the old field, then update your table once you get the value.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 121
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Passing a variable to another page

 
0
  #3
Feb 16th, 2008
you can do that using javascript too :
use an html textbox and html button instead of server controls :
<input type="text" id="textbox1" />
<input type="button" id="button1" value="myButton" onclick="document.location= 'mySecondPageUrl?param=' + document.getElementById('textbox1').value />

in your second page you can get the value using Request objects QueryString property.

void secondPage_Load(object sender, EventArgs e)
{
int i = Convert.ToInt32(Request.QueryString["param"]);
}

Then you can do whatever you want with that number.
Last edited by serkan sendur; Feb 16th, 2008 at 1:17 pm.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Passing a variable to another page

 
0
  #4
Feb 18th, 2008
Just put it in Session or QueryString.
In first page set on button click event:
  1. Session("Number") = Me.MyTextbox.Text.Trim
  2. --or--
  3. Response.Redirect("Secondmenu.aspx?Number=" & Me.MyTextbox.Text.Trim)

Then in second page use something like this:
  1. Dim myFilter as Int16
  2. Try
  3. myFilter = CInt(Session("Number"))
  4. --or--
  5. myFilter = CInt(Request.QueryString("Number))
  6. Catch ex As Exception
  7. --code for error handling--
  8. End Try
  9.  
Last edited by ManicCW; Feb 18th, 2008 at 4:06 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Passing a variable to another page

 
0
  #5
Feb 18th, 2008
Originally Posted by Dano56 View Post
I need help getting a variable from one page displayed onto another. I have two pages, mainmenu.aspx and secondmenu.aspx. mainmenu.aspx contains Textbox1 which contains some user-entered number in it. When the user clicks on Button1 on mainmenu.aspx, I need the table, Table1, on secondmenu.aspx to reflect that new selection.

Thanks for any help or ideas.
hi Dano56,
I think answer for your query is QueryString OR Session. But according to me prefer querystring so, i given following example as follows.
For ex. You want to go from Page1 on click event of button it redirects you at Page2 then pass query string along with Page2's URL. Suppoese your query string name is "qstr" then on click of button following steps should occur.
Button_click
{
Response.Redirect(Page2.aspx?qstr=id);
}
Then 1) on the load event of page2 check for query string
2) update your page base on querystring

To get the value of the query string on the page2 load event as follows

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["qstr"] != null)
{
string qstr1 = Request.QueryString["qstr"].ToString (); // statement for accessing querystring from aspx.cs file
}
}


To get the value of the query string from any class as follows

System.Web.HttpContext.Current.Request.QueryString["id"].ToString (); //statement for accessing querystring from any .cs file

Hope this will help you.
Thanks & Regards
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: bbqchickenrobot is an unknown quantity at this point 
Solved Threads: 2
bbqchickenrobot bbqchickenrobot is offline Offline
Light Poster

Re: Passing a variable to another page

 
0
  #6
Feb 19th, 2008
You should only use session variables for information related to the session... but of course, this will work...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC