How do you inspect HTML controls in compiled C#?

G

Guest

I have a C# application that builds dynamic HTML and renders it. Because it
is rendered in this way, the input controls are not server controls. I write
the entire page, which has a variable number of detail lines for an order. I
want the user to be able to change values on these detail lines and hit an
'update' button. I know how to do this in Javascript, but I'd like to be
able to inspect the controls that come back to my C# program during a
Postback. Since these are not server controls, they are not available in
Page.Controls. What is the 'proper' way to inspect these inside of the
compiled C# program? Right now I'm parsing them out through javascript, and
passing them through cookies, but there has to be a better way than this,
isn't there?
 
K

Kevin Spencer

Hi Brian,

Do you have Visual Studio.Net? If so, three are oodles of ways to inspect
process and data in your app, using BreakPoints, Watches, etc.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
G

Guest

Yes, running .NET, but what I meant was I needed to get the value of the
controls in my C# program. Programatically I need to check the value of the
controls. I can't figure out how to do it through any normal object.
 
K

Kevin Spencer

When you say "running .Net," are you referring to the .Net platform, or, as
I asked, Visual Studio.Net?

In any case, the question is moot, since you want to do it programmatically.
Your best bet is to use WebControls or HtmlControls to do this. That is what
they are designed for. Any other solution is going to be problematic.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
G

Guest

Maybe I'm approaching this wrong then. My end result is to have a web page
that shows a variable number of 'detail' lines. These are pulled from a
database. I put a server control on my page that internally renders the
HTML. It builds the entire page dynamically, since the # of detail lines is
not know until the actual order is pulled up. I have checkboxes on each of
the detail lines, so that a user can check a line, and click a button to see
more detail for that line.

The problem is, that since the entire page was built with dynamic HTML, I'm
having trouble finding out which line is checked. Currently, I have a couple
of lines of java script that determine which line is checked, put the value
in a cookie, and pass that to my C# program. It just seems to me that there
should be a way in my C# program to figure out which lines are checked.
Since this whole page is built dynamically, I don't have web controls or html
controls. Any ideas?
 
K

Kevin Spencer

Hi Brian,

Okay, you say you "put a server control on my page that internally renders
the HTML." And "It just seems to me that there should be a way in my C#
program to figure out which lines are checked." Finally, you also mention
that you "have a couple of lines of java script that determine which line is
checked, put the value in a cookie, and pass that to my C# program." In
fact, you HAVE figured out a way in your program to figure out which lines
are checked.

Perhaps you are misunderstanding ASP.Net a bit, but you certainly know how
to solve a problem! And that is what a programmer (and a program) does. Let
me see if I can clear it up a bit for you and give you a better day.

ASP.Net is all about HTML and HTTP. What the server-side part of the app
does is to create HTML and respond to browser requests, in essence. In other
words, ASP.Net is about working in a stateless HTTP environment in which the
client is disconnected from the server, and HTML is the UI "language" if you
will. HTTP is all about messaging, sending messages back and forth between
the browser and the server.

So, in fact, an ASP.Net application has both a server-side and a client-side
aspect to it. The fact that the server-side code renders the client-side
HTML may be confusing you, but in fact, both are inseparable (although
separate) parts of the same application.

The built-in Microsoft Server Controls, as well as any custom Server
Controls you may create and/or use, do essentially what your solution does.
The only diffrence is in the methodology, and even that is similar. MS
Server Controls render both HTML and JavaScript, as JavaScript is almost the
only way to create a process on the client, in the browser. Server Controls
handle client-side events by creating and using JavaScript and hidden form
fields. The JavaScript on the client is wired up to client-side form
elements via JavaScript event handlers. When a button is clicked, for
example, a JavaScript event handler is fired that puts the ID of the button
into one hidden form field, and an "argument" or a set of arguments, if any,
into another. It then posts the form, which sends the form data, including
the event data, back to the server, where the server-side code reacts to it.

Your solution is proprietary, and doesn't follow the ASP.Net programming
model very closely, but it does essentially what the ASP.Net programming
model does. The ASP.Net programming model is more extensible, and follows a
design pattern that is extremely well thought-out. You may want to follow it
more closely in the future, but that is really of secondary importance to
solving the problem, which you have done quite well.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top