Version: ASP.NET 1.0
Compatibility: ASP.NET 1.0
Category: ASP.NET
I'm frequently asked how to pass parameters from one page to another page in ASP.NET.
This is a beginner's question and every ASP.NET developer should master this concept. So if you don't already know the answer, then definitely read on...
I get asked this alot as our charting tool is implemented via two web pages. One web page has a server chart control that renders as HTML (either an IMG or CLSID object tag.) The second page has a server control that streams the bits constituting the object created via HTML from the first page. This process is ideal for web-farm environments as it's purely scaleable.
To help visualize the problem. Take a look at www.gigasoft.com/financial.aspx
On the left hand side of chart the user can select a stock symbol to load the corresponding stock data.
To implement such a site...
Declarations:
'none
CODE:
'Within the Page_Load for the form1 (Financial.aspx.cs)
// Add a parameter to pass volume checkbox data
string s = "";
if (VolumeCheckbox.Checked == true)
s = s + "Volume=1";
else
s = s + "Volume=0";
// Add a parameter to pass symbol combobox data
s = s + "&Symbol=" + SymbolComboBox.Value.ToString();
PegoWeb1.ImageUrl = "Financial2.aspx?" + s;
Within the Page_Load of the form2.
string sVolume;
string sSymbol;
sVolume = this.Request.QueryString.Get("Volume");
sSymbol = this.Request.QueryString.Get("Symbol");
Note the "?" at end of ImageUrl = "Financial2.aspx?".
Note you can string together multiple parameters separating with "&" symbol.
0 comments:
Post a Comment