Is it possible to retrieve a text from a URL or page content by using something like ImageUrl property on the Image Control?
Ex in image:
<asp:Image runat="server" id="Image1" ImageUrl="getImage.aspx?id=2" />

Let's say I have this code on getText.aspx

Imports System.Data
Imports System.Data.SqlClient

Partial Class getText
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim theid As Integer = Request.QueryString("id")
        Dim con As New SQLConnection(ConnectionString)
        Dim cmd As New SqlCommand("SELECT somefield FROM sometable WHERE id=" & theid)
        Dim sda As New SqlDataAdapter(cmd)
        Dim ds As New Dataset

        sda.Fill(ds)

        If ds.Tables(0).Rows.Count > 0 Then
            Response.Write( ds.Tables(0).Rows(0).Item("somefield").toString )
            For i = 1 To ds.Tables(0).Rows.Count - 1
                Response.Write(", " & ds.Tables(0).Rows(i).Item("somefield").toString)
            Next
        End If
        con.Close
    End Sub
End Class

and having this database struture on the database,

  id              somefield
  1               student1
  2               student2
  2               professor1
  3               professor2

Assuming that example is running on Label:
<asp:Label runat="server" id="Label1 TextUrl="getText.aspx?id=2" />

Output:
Label1.Text = "student2, professor1"

I know how to do it on javascript but I don't know how on ASP.NET
It is something like

<script src="getText.js" type="javascript"></script>

I will be using it on Datalist's item template

Please help,
Michael

PS:
Sorry for my poor english.

Recommended Answers

All 5 Replies

Let me try to get some clarification. You're wanting to access the value in a control on one page, let's call it pageA.aspx, from a completely different page, pageB.aspx? I think the better option would be to pass the value that you need from pageA to pageB either using a QueryString object or a Session variable, depending on the situation. If i've misunderstood what you're trying to do, let me know

I will be using it on a "forum-like" asp page. I am using a Datalist control to list all forum categories. The part that I am asking will be used on who are the people administrating the page, somewhat like that.

Is it possible to retrieve a text from a URL or page content by using something like ImageUrl property on the Image Control?
Ex in image: <asp:Image runat="server" id="Image1" ImageUrl="getImage.aspx?id=2" />

Sure it is... This is technique i have used when building a captcha solution. I generate the image using random numbers and background lines in an aspx page, then on the page that contains the image control, I reference the captcha aspx page using the ImgURL attribute.

Sure it is... This is technique i have used when building a captcha solution. I generate the image using random numbers and background lines in an aspx page, then on the page that contains the image control, I reference the captcha aspx page using the ImgURL attribute.

I know how to run that code on images, I actually got the idea of my problem from that. Maybe you misunderstood my explanation. =P

The idea is to get a string of characters from another asp.net page via "primary key" that will be retrieved by Request.QueryString, and pass it on a control that can hold a text, or even a simple <p> tag.

I'm still thinking and browsing over the web for some topic on how to do that on text.

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.