C# page write to web page

I have a C# page that stands on it own, independently.  It is just a C# file, it is NOT the code behind for an ASP.NET page.  I need to write data to the ASP.NET page I am on, whether it be writing to a Label that is on the page, or with a Response.Write().  Reponse is not available on the C# page I am using since it is a stand alone file.  Any ideas how I can get this page to work?
LVL 15
melli111SharePoint Administrator / DeveloperAsked:
Who is Participating?
 
GeoffSuttonCommented:
Ok.  You should be able to derive the page through the source objects parent.  If this is a generic event used for multiple item type rather than a single item (such as a button click event) then you would likely have to cast the source to a webcontrol to get the page, to allow you to write to the page.
0
 
GeoffSuttonCommented:
I will need some code examples.  You are attempting to write to a page using a class file?  If so the easiest way will be to call the necessary functions sending the page response object to write to.  Also in the interests of keeping things generic, you might choose to use literal controls on your page where you might be writing.  That will allow you to post either text or HTML to simplify your responses.

Otherwise there is really no way to connect between a page and code that is not part of the page class, unless you decide to go with AJAX functions to handle the passing of data.

HTH,

as I said, code samples and exactly what you are attempting to accomplish will help to get your question answered more to the point of what you are looking for.

Geoff
0
 
mrjoltcolaCommented:
Agree with Geoff, show us a sample.

I assume you have an old-fashioned "CGI" style program that is spitting out HTML? In that case, you either need to do your own server-side parsing (regex replacement, etc.) of the HTML on its way out. If you want to change Labels on the fly (after page load) you'd do it in Javascript with the DOM API. But I'm just guessing here what you are talking about. Not sure what you mean "ASP.NET" page if there is no asp page involved.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
MajorBigDealCommented:
You could pass the current context into the stand-alone c# and then use that to do do a write response.  For example:

In your code-behind:  ManipulatePage(HttpContext.Current);

In your stand-alone c#:

public void ManipulatePage(HttpContext currentContext)
{
currentContext.Response.Write("Hello");
}

That way you could call ManipulatePage from anywhere without having to replicate the write response code in each code-behind.
0
 
melli111SharePoint Administrator / DeveloperAuthor Commented:
I guess I am trying to think of a way where I could have an even fire in the stand-alone C# fire code that writes back to the originial code behind page.
0
 
GeoffSuttonCommented:
You cannot, unless you link that function to an event...

class testCode{
  function calledEvent(object sender, eventArgs e){
  //    Do something here
  }
}

Then in your page you can wire up the event:

btnTestButton.onClick+=testCode.calledEvent;

This is just off the top of my head, and is pseudocode - The intellisense will direct you to the exact syntax to use.  However, if you are going to do that, it is just as simple to call the calledEvent function from the event code in the main page.  There is really no significant advantage one way over the other that I can see.

HTH,
Geoff
0
 
melli111SharePoint Administrator / DeveloperAuthor Commented:
I have a condition that I would like to have trigger the event of writing to the ASP.NET page, so I will add the Event handler to my code
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.