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

One's house style oughtn't to be visible from outer space.

Benjamin Dreyer



Navigation





<October 2021>
SMTWTFS
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

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 - 9/13/2021

Totals
Posts - 2638
Comments - 2643
Hits - 2,415,907

Averages
Entries/day - 0.39
Comments/entry - 1.00
Hits/day - 361

Updated every 30 minutes. Last: 10:30 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] |