Hi

I have a code that i get a value from a text box in the web page and i want to display the result in another web page. how do i do it?

the code is below:

string key = "aaaa";
            string isbn = TextBox1.Text;

            string sUrl = ("https://api.bookshare.org/book/isbn/" + isbn + "/format/json?api_key=" + key);

            if (IsPostBack)
            {

                WebRequest request = WebRequest.Create(sUrl);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();

            }

appreciate a reply
thanks

based on your code it appears that you already have that URL assigned to the string sUrl. Therefore, you can simple do a response.redirect.

response.redirect(sUrl)

i guess i wasn't cleaar
i don't want to direct to the URl that is in my code

but i need to display the result from the sUrl to a page Result.aspx in my project
how do i do that?(formattgin the content from the SUrl needs too display in Result.aspx)

thanks

You can send that information in various ways. One simple method is to use a query string. Or you can save the info in a session variable.

For a query string send the values like this .aspx?a=1&b=2. Try then .

 Response.write("result.aspx?" + sUrl);

On the result page, extract the query string with request.querystring("sUrl") in the page load.

Or like I mentioned, store the info in a session cookie and retrieve it on the result page.

hi
i used te query string method
when i put the code

 Response.write("result.aspx?" + sUrl);

gives me an error saying no overload method for write with 2 arguments?

then i was trying to use the session variable i added the code

Session["Result"] = response;

how to i access the "Result" session from the Result.aspx web page

appreciate a reply
thanks

You should be able to access the session variable on the result page as follows:

string sURL = (string)Session["Result"];

when i add this in the Result.aspx page it does not display anything

 string a = (string)(Session["Result"]);
 Response.Write(a);

the Default.expx sends a null value to the session variable. how to i make sure that the data is being sent to the session variable?

In your default page, try...

 Session["Result"] = sUrl;

yes that is what id did

 string key = "1111111111";
            string isbn = TextBox1.Text;

            string url = ("https://api.bookshare.org/book/isbn/" + isbn + "/format/json?api_key=" + key);

            if (IsPostBack)
            {
                WebRequest request = WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();

                Session["Result"] = response;

                reader.Close();
                dataStream.Close();
                response.Close();
            }

and I want to display the session variable 'Result' in the Result.aspx web page

when i do it as

if (Session["Result"] != null)
                {
                    string a = (string)(Session["Result"]);
                    Response.Write(a);

                }

the response is not displayed?
a returns a null value

ok
i got it

Default.aspx


 string key = "aaaaaaaaaaaaa";
            string isbn = TextBox1.Text;

            string url = ("https://api.bookshare.org/book/isbn/" + isbn + "/format/json?api_key=" + key);



HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.Method = "POST";
            httpWebRequest.ContentType = "application/x-www-form-urlencoded";

            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream responseStream = httpWebResponse.GetResponseStream();
            StreamReader streamReader = new StreamReader(responseStream);
            string response = streamReader.ReadToEnd();

            Session["r"] = response;
            Response.Redirect("Result.aspx");

Result.aspx

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(Session["r"]);            
        }

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.