Click here to Skip to main content
15,885,278 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Verify idle time? Pin
yibiBrown18-Apr-08 4:42
yibiBrown18-Apr-08 4:42 
GeneralRe: Verify idle time? Pin
led mike18-Apr-08 5:43
led mike18-Apr-08 5:43 
AnswerRe: Verify idle time? Pin
Amit Agarrwal17-Apr-08 19:00
Amit Agarrwal17-Apr-08 19:00 
General.NET TRANSACTION Pin
AumSingh17-Apr-08 6:35
professionalAumSingh17-Apr-08 6:35 
GeneralRe: .NET TRANSACTION Pin
led mike17-Apr-08 7:54
led mike17-Apr-08 7:54 
GeneralRe: .NET TRANSACTION Pin
Christian Graus17-Apr-08 14:26
protectorChristian Graus17-Apr-08 14:26 
GeneralRe: .NET TRANSACTION Pin
AumSingh17-Apr-08 22:17
professionalAumSingh17-Apr-08 22:17 
GeneralHooking the output of user controls Pin
Christopher Duncan17-Apr-08 3:59
Christopher Duncan17-Apr-08 3:59 
First, a definition of context. I'm working with user controls, which utilize the .ascx markup with the codebehind pointing to the .cs, basically the same model as a page. This is not the same as custom server controls, which are precompiled and generate the html output by hand. I have a significant number of user controls which display grids and other non trivial forms of output.

What I'm looking to do is build snippets of script code that people can copy & paste into their own web site, thus displaying the data that I feed them through the script. An example of this might be:

<script src="http://www.website.com/ShowList.aspx"></script>

the result of which would be displaying the grid view on the site who pasted this script into their page. This is a fairly common technique for javascript output. If I wanted to print "Hello, World!" on your web page, in the Page_Load of ShowList.aspx I could do something like this:

<br />
Response.Write("document.write('Hello World!');");<br />


By pasting the above script onto your page, Hello, World! magically appears. So far, so good. If I wanted to output something more complex, like a table, I could update the output to instead call document.getElementById() of some predefined div and then set the element's innerHTML to the HTML of the table, etc. Then the table would appear on your page, as if by magic. Again, no problem to do.

Now we get to the fun part. I don't want to reinvent the wheel and code the logic of dozens of controls all over again, using this model, so that I can use them as output in the aforementioned scripting scenario. What I really want to do is effectively hook into the output of the user control and redirect that output for use by the script. Here's a pseudo code idea of what I mean:

  1. Page_Load of ShowList.aspx spits out opening javascript, i.e. document.getElementById() our div
  2. UserControlOne.ascx outputs a grid control, we redirect the final html output of this grid to a routine in ShowList
  3. This routine takes the html and assigns it to the innerHTML of the element we found in step 1
  4. We now bask in the glory of our grid being automagically output to the user of the one line of script code


As you can see, where the rubber meets the road is hooking the html output of our user control so that we can redirect it to the output stream being formatted as javascript, and that's the part I'm having difficulty with. In the old C++ / MFC days, it was an ongoing business of finding out where you needed to hook something, hacking your way into it and redirecting it to where you wanted it to go. The fact that you had the full MFC code that you could step through in your debugger helped immensely, of course.

Unfortunatly, my knowledge of the ASP.NET architecture isn't yet that deep, and so I'm struggling trying to figure out how to hook the output of a user control and point it where I want it to go, i.e. the example above.

Apologies for the long explanation, but I asked this question last week and got little response because I really didn't ask the question very well. Hopefully this will give the knowledgable among you sufficient information about what I'm trying to accomplish that you can point me in the right direction.

And of course, any help would be most gratefully accepted!


Christopher Duncan
Author of
The Career Programmer and Unite the Tribes
Coming soon: Got a career question? Ask the Attack Chihuahua!
www.PracticalUSA.com

GeneralProblem with Basic ASP.NET Pin
Vimalsoft(Pty) Ltd17-Apr-08 3:38
professionalVimalsoft(Pty) Ltd17-Apr-08 3:38 
GeneralRe: Problem with Basic ASP.NET Pin
Herman<T>.Instance17-Apr-08 3:55
Herman<T>.Instance17-Apr-08 3:55 
GeneralRe: Problem with Basic ASP.NET Pin
Vimalsoft(Pty) Ltd17-Apr-08 4:00
professionalVimalsoft(Pty) Ltd17-Apr-08 4:00 
GeneralRe: Problem with Basic ASP.NET Pin
Herman<T>.Instance17-Apr-08 4:08
Herman<T>.Instance17-Apr-08 4:08 
GeneralRe: Problem with Basic ASP.NET Pin
Vimalsoft(Pty) Ltd17-Apr-08 20:02
professionalVimalsoft(Pty) Ltd17-Apr-08 20:02 
GeneralRe: Problem with Basic ASP.NET Pin
Herman<T>.Instance17-Apr-08 20:27
Herman<T>.Instance17-Apr-08 20:27 
GeneralRe: Problem with Basic ASP.NET Pin
Vimalsoft(Pty) Ltd17-Apr-08 21:20
professionalVimalsoft(Pty) Ltd17-Apr-08 21:20 
GeneralRe: Problem with Basic ASP.NET Pin
Herman<T>.Instance17-Apr-08 23:19
Herman<T>.Instance17-Apr-08 23:19 
GeneralRe: Problem with Basic ASP.NET Pin
Vimalsoft(Pty) Ltd18-Apr-08 3:10
professionalVimalsoft(Pty) Ltd18-Apr-08 3:10 
GeneralRe: Problem with Basic ASP.NET Pin
Christian Graus17-Apr-08 14:33
protectorChristian Graus17-Apr-08 14:33 
GeneralQuestion Pin
nithydurai17-Apr-08 3:04
nithydurai17-Apr-08 3:04 
GeneralRe: Question Pin
J4amieC17-Apr-08 3:25
J4amieC17-Apr-08 3:25 
GeneralRe: Question Pin
led mike17-Apr-08 7:55
led mike17-Apr-08 7:55 
GeneralRe: Question Pin
Rocky#17-Apr-08 3:25
Rocky#17-Apr-08 3:25 
GeneralRe: Question Pin
Ashish Sehajpal17-Apr-08 5:59
Ashish Sehajpal17-Apr-08 5:59 
GeneralRe: Question Pin
Vasudevan Deepak Kumar17-Apr-08 21:06
Vasudevan Deepak Kumar17-Apr-08 21:06 
QuestionDropdownlist DataTextField Pin
Saba0217-Apr-08 3:00
Saba0217-Apr-08 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.