943,685 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 11212
  • ASP.NET RSS
Feb 15th, 2008
0

Passing a variable to another page

Expand 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dano56 is offline Offline
1 posts
since Feb 2008
Feb 16th, 2008
0

Re: Passing a variable to another page

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.
Reputation Points: 9
Solved Threads: 3
Light Poster
bbqchickenrobot is offline Offline
43 posts
since Feb 2008
Feb 16th, 2008
0

Re: Passing a variable to another page

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Feb 18th, 2008
0

Re: Passing a variable to another page

Just put it in Session or QueryString.
In first page set on button click event:
ASP.NET Syntax (Toggle Plain Text)
  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:
ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Feb 18th, 2008
0

Re: Passing a variable to another page

Click to Expand / Collapse  Quote originally posted by Dano56 ...
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
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008
Feb 19th, 2008
0

Re: Passing a variable to another page

You should only use session variables for information related to the session... but of course, this will work...
Reputation Points: 9
Solved Threads: 3
Light Poster
bbqchickenrobot is offline Offline
43 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to register page for a web user control codebehind??
Next Thread in ASP.NET Forum Timeline: [B]DropDownList, TextBox to GridView.....[/B]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC