0

HI,

I have a text message in a C# class file that i want to display in a web page in asp.net. from the C# class file how do i access the web page or how do i display the value in the web page.

Appreciate a reply

thanks

4
Contributors
18
Replies
56
Views
4 Years
Discussion Span
Last Post by ggamble
0

First of all, that's not a good practice. The best way, in my opnion, would be to have an code behind that uses your class, get the message and set it to the html.

But, if you really want to do it...

If you just want to write something exatly after the last thing was wrote, use:
System.Web.HttpContext.Current.Response.Write("My Text")

If you want to write the text in some specific place, I only know a very ugly work arround, using JavaScript:

System.Web.HttpContext.Current.Response.Write(@"

    <script type=""text/javascript"">

        // Set a timeout of 1 second, in case the script is added at the beging of the page
        // and the DOM is not ready yet.
        setTimeout(function() {

            document.getElementById("YourElementId").innerHTML = "Your Text";

        }, 1000);

    </script>

");
0

hey
do you know any other way rather than javascript that i can write the result to the Result.aspx web page (the result comes from the handler.cs file)

appreicate a reply
thanks

0

It seems to me that you simply want to display correct? Not sure why you are using response.write. Don't you have any controls on your .aspx page that you can access? For example, if you have a label control, from your code behind, you can access its text property to display information. For example...

label1.text = "My results";

0

i have a web page Result.aspx and i have a class file call Handler.cs. I am trying to write to the Result.aspx from the Handler.cs file.
So i cannot access the web page controls?

is there a direct way to write to the web page from the Handler.cs class file

appreciate a reply
thanks

0

Yes, I understand...or I think so... I would assume that you are accessing the class located in handler.cs from the code behine page --> result.aspx.cs? Aren't you?

0

I am trying to access result.aspx from handler.cs

Ok, sorry about that... i am not sure how to advise you on that. Maybe AleMonteiro, or another member may have some better advice for you.

0

If your method is set to public it can write directly when called:

`public string  MakeText()
{
    string results;
    // Add code here
    return results;
}

This goes in aspx page, and will output what ever MakeText returns on page load.

<%= MakeText(); %>`
0

hey ggamble regarding the post you posted

I have a method in the Handler.cs and I want it to send it to be displayed in the Result.aspx web page. how do i solve this

the code you provided was to add the "<%= MakeText(); %>" to the Result.aspx page adn the method MakeText should be in the Result.aspx.cs file right?

but how do i display the data from Handler.cs file to the Result.aspx page

appreciate a reply
thanks

0

Anisha,

you could call your Handler.cs method inside the the MakeText() in Result.aspx.cs.

If you want Handler.cs to write your Result.aspx, you have to use one of the methods I suggest in my first post.

0

AleMonteiro,
yes i created the object of the Handler.cs in the Result.aspx web page page load method.

but how do i push the data from the handler.cs class mathod to the web page.

or how do i tell the Handler.cs method public stirng displayResuly() {} to display in the Result.aspx page

appreciate a reply
thanks

0

Sorry for the late reply ...

You can call the handler.cs in the public method you use in the Result.aspx.cs. MakeText() is what you called it. Make sure its public, and then you can call your Handler.cs method.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.