Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

passing arguments into an aspx page

Posted on 2009-12-17
5
Medium Priority
?
777 Views
Last Modified: 2012-05-08
I've used the below to pass arguments into a windows form.  The form uses these arguments to run a stored procedure to fill a datagrid. I'm passing the arguments from an outside application.
I'm new to aspx pages.  Can you point me the direction of how I could do something similar for opening an aspx page (c#)?  

static void Main(string[] args)
{
      argument1= (args[0]);
      argument2 = (args[1]);
      argument3 = (args[2]);

      Application.Run(new Form1());
}
0
Comment
Question by:LATurk
5 Comments
 
LVL 11

Accepted Solution

by:
five22bags earned 2000 total points
ID: 26073426
You will want to user the querystring. If you call an aspx page like so:

http://www.mysite.com/processme.aspx?id=1&this=that

you can access it like this in  the codebehind (processme.aspx.cs):

protected void Page_Load(object sender, EventArgs e)
    {
        string arg1 = Request.QueryString["id"];
        string arg2 = Request.QueryString["this"];
    }

Open in new window

0
 
LVL 7

Expert Comment

by:waltersnowslinarnold
ID: 26073511
When you call an aspx page

Response.Redirect("~/WebPage.aspx?arg1=+''argument1"&arg2="argument2"&arg3="argument3");

Now, When you reach the destination page. You should request these querystring value as follows

string args1=Request.QueryString["arg1"];
string args2=Request.QueryString["arg2"];
string args3=Request.QueryString["arg3"];

Now, use the values arg1,arg2,arg3 as an argument for the Stored procedure..
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 26073541
HI

you can pass that information through get method, or through session variables.

Through get method,

response.redirect("page.aspx?id1=" & val1 & "&id2=" & val2)

to retrieve in other page:

request.querystring("id1")
request.querystring("id2")

or through session variables

session("id1") = val1
session("id2") = val2
response.redirect("page.aspx")

to retrieve in other page:

id1 = session("id1")
id2 = session("id2")
0
 

Author Closing Comment

by:LATurk
ID: 31667403
Perfect!  Thank You!
0
 

Expert Comment

by:Sadiko
ID: 26073755
There are several ways, the easiest is via QueryString:

You create a button on the main page, for example default.aspx

You add a function in the OnClick property, in this case "TESTBUTTON_ONCLICK"

Now we get to the part of the code, Defautl.aspx.cs

protected void TESTBUTTON_ONCLICK(object sender, EventArgs e)
{
        Response.Redirect("Default2.aspx?param1=Hello&param2=World&param3=!");
}

Now in Page_Load property of the page you're going through data

String auxStr = String.Empty;

auxStr += Response.QueryString["param1"].ToString();
auxStr += Response.QueryString["param2"].ToString();
auxStr += Response.QueryString["param3"].ToString();

or

auxStr += Response.QueryString[0].ToString();
auxStr += Response.QueryString[1].ToString();
auxStr += Response.QueryString[2].ToString();

and...

Response.Write(auxStr);


Another way is to add the property "Action" page Default Default2.aspx name, and you must use Input controls, and in the Page_Load Default2 takes the values Request.Form [ "nameObject"].

I hope you serve any of them, Best Regards

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

579 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