[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# page write to web page

Posted on 2011-05-02
7
Medium Priority
?
626 Views
Last Modified: 2013-12-14
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?
0
Comment
Question by:melli111
7 Comments
 
LVL 10

Expert Comment

by:GeoffSutton
ID: 35507127
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
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 35507223
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
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 35509372
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Author Comment

by:melli111
ID: 35723687
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
 
LVL 10

Expert Comment

by:GeoffSutton
ID: 35723724
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
 
LVL 15

Author Comment

by:melli111
ID: 35723848
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
 
LVL 10

Accepted Solution

by:
GeoffSutton earned 2000 total points
ID: 35723869
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question