About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 30 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Google Ads

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

This process of digging up the details and learning how things work leads down many side streets and to many dead ends, but is fundamental (I think) to understanding something new. Many times in my books I have set out to write how something works, thinking I know how it works, only to write some test programs that lead me to things that I never knew. I try to convey some of these missteps in my books, as I think seeing the wrong solution to a problem (and understanding why it is wrong) is often as informative as seeing the correct solution.

W. Richard Stevens



Navigation





<June 2018>
SMTWTFS
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 6/22/2018

Totals
Posts - 2503
Comments - 2574
Hits - 2,057,505

Averages
Entries/day - 0.46
Comments/entry - 1.03
Hits/day - 376

Updated every 30 minutes. Last: 8:41 PM Pacific


  04:54 PM

When you read a page on MSDN, you can both rate it and enter comments. Other people can see the ratings, but the comments are not visible to all.

Now and again we'll have a look at a topic and wonder about the ratings. (Well, we generally wonder only about bad ratings. :-) ) There have been a few that we thought were pretty useful topics that have gotten low ratings. Then when we look at the comments, we'll find out that, oh, say, the code in the topic has a bug in it. There's a way to get yerself a low rating.

And do you want a really, really low rating? How about if you leave the sample code out altogether? Uh ... oops. We did this in a topic I was looking at today[1]:

How to: Locate the Web Forms Controls on a Page by Walking the Controls Collection

The comments were surprisingly un-vicious, considering. Anyway, here's the missing code:
' VB
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
<title>Locate the Web Forms Controls on a Page by Walking the Controls Collection</title>
</head>

<script runat="server">
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim allTextBoxValues As String = ""
Dim c As Control
Dim childc As Control
For Each c In Page.Controls
For Each childc In c.Controls
If TypeOf childc Is TextBox Then
allTextBoxValues &= CType(childc, TextBox).Text & ","
End If
Next
Next
If allTextBoxValues <> "" Then
Label1.Text = allTextBoxValues
End If
End Sub
</script>

<body>
<form id="form1" runat="server">
<asp:Button id="Button1" runat=server />
<asp:Label id=Label1 runat=server></asp:Label>
</form>
</body>
</html>
// C#
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
<title>Locate the Web Forms Controls on a Page by Walking the Controls Collection</title>
</head>
<script runat="server">
private void Button1_Click(object sender, System.EventArgs e)
{
string allTextBoxValues = "";
foreach (Control c in Page.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is TextBox)
{
allTextBoxValues += ((TextBox)childc).Text + ",";
}
}
}
if (allTextBoxValues != "")
{
Label1.Text = allTextBoxValues;
}
}

</script>
<body>
<form id="form1" runat="server">
<asp:Button id="Button1" runat=server />
<asp:Label id=Label1 runat=server></asp:Label>
</form>
</body>
</html>
[1] It's not that we left it out, of course. There was some build problem and the code sample was dropped out of the topic. Same effect either way, tho.

[categories]   , ,

|