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

Recommended Answers

All 18 Replies

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>

");

will ake a look at it
thanks

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

Your .cs file is an codebehind page?

Yes
That is the place I wrote all the processong

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";

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

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?

The other way around
I am trying to access result.aspx from handler.cs

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.

Is there any way to do it or do I have to change my approach

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(); %>`

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

hi appreciate a reply
thanks

hi
i would appreciate a repy
thanks

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.

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

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.

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.