About

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

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

Correcting one's drinking buddies on grammar is a good way to end up drinking alone.

"Lancaster"



Navigation





<April 2024>
SMTWTFS
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

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  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 11/30/2023

Totals
Posts - 2652
Comments - 2673
Hits - 2,654,452

Averages
Entries/day - 0.35
Comments/entry - 1.01
Hits/day - 349

Updated every 30 minutes. Last: 10:28 PM Pacific


  11:48 PM

One of the many areas of ASP.NET where I could use to have more expertise is that of injecting client script into pages. I've often done it manually (e.g, by using control.Attributes.Add), but the Page class also has a number of methods for injecting client script in a more structured away. These include:

RegisterClientScriptBlock
RegisterStartupScript
RegisterOnSubmitStatement
GetPostBackClientEvent
GetPostBackHyperlink
GetPostBackEventReference

The problem -- a problem -- is that the documentation for these methods is, mmm, not so great. Moreover, the documentation lacks an overview that pulls all these together and provides a nice chart telling you under what circumstances to use which, um, method (member or approach). A task for the Whidbey docs.[1]

There are some articles on this already available, which are somewhat helpful:Anyway, based on what I read, I thought I'd play around a little. RegisterOnSubmitStatement sounded interesting, so I experimented to see if I could write the minimal-case example of confirming that you want to submit a page. Here's what I came up with:
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load()
Dim script As String = "return DoConfirm();"
Page.RegisterOnSubmitStatement("", script)
End Sub

Sub Button1_Click(sender As Object, e As EventArgs)
Label1.Text = "Posted @ " & DateTime.Now.ToString()
End Sub
</script>
<html>
<head>
<script language="javascript">
function DoConfirm()
{
return confirm("Do you want to submit?");
}
</script>
</head>
<body>
<form runat="server">
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>

[1] According to this article, the various Page methods for client script are being moved to a ClientScript object.

[2] He retired. Already.

[categories]  

[2] |