Can a user control get data from another page?

S

Sunil Menon

Dear All,
I have developed a User Control that displays data fetched from the
database. I would like to develop the UserControl to dynamically call
an aspx page with parameters and set the content of that page as an
innerHTML of its control. Is this possible?
For e.g. On Page_load of WebForm1.aspx that has the UserControl I
would like to...
Page_Load(...)
Dim sData as string = oUserControl1.getData("WebForm2.aspx)
oUserControl1.innerHTML = sData
end function

If this is not possible is there any other workaround?

Please help...

TALIA
Many Regards
Sunil
 
Joined
Sep 21, 2006
Messages
1
Reaction score
0
Hi Sunil,

You can do that after getting the web response from the function GetContent(string url) used here. Here url is the fully qualified path. (e.g., http://localhost/TestProject/MainPage.aspx?Field1=value1&Field2=value2)

So you can use the function as follows:

oUserControl1.innerHTML = GetContent("http://localhost/TestProject/WebForm2.aspx")

You have to pass the parameters using Query String.

Cheers!!!


----------------------------------------------------------

using System.IO;
using System.Net;

-----------------------------------------------------------

public string GetContent(string url)
{
WebRequest wReq = HttpWebRequest.Create(url);
StreamReader sr = new StreamReader(wReq.GetResponse ().GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
return result;
}

-----------------------------------------------------------
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top