Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2007, 07:06 PM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cht 23, pg 890 ViewState, agh!

Ok, I've downloaded the code and looked in the erata.

I've been stuck on this for hours, and the code doesn't work.

I click the button and I still only get the javascript popup "please enter a number" or "the data is valid".

The below code doesn't set the .Text property like it should:

    Protected Sub Button1_Click(ByVal sender As Object, _
                                ByVal e As System.EventArgs)
        Me.WebCustomControl1_1.Text = "CustomControl"
        Me.TextBox1.Text = "StandardTextbox"
    End Sub





The paragragh on page 892 also says "Click the 'Populate' button" and "Click the 'Postback' button"

but there are NO 'Populate' or 'Postback' buttons! in the page or downloaded code! :(
 
Old March 1st, 2007, 07:15 PM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here's the control code:

Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("Text"), _
 ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")> _
Public Class WebCustomControl1
    Inherits System.Web.UI.WebControls.WebControl
    Implements System.Web.UI.ICallbackEventHandler

    Dim _text As String

    <Bindable(True), Category("Appearance"), DefaultValue(""), Themeable(False)> _
    Property [Text]() As String
        Get
            _text = CStr(ViewState("ControlText"))
            If (_text = Nothing) Then
                Return String.Empty
            End If

            Return _text
        End Get

        Set(ByVal Value As String)
            ViewState("ControlText") = Value
        End Set
    End Property




    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
        output.RenderBeginTag(HtmlTextWriterTag.Div)

        output.AddAttribute(HtmlTextWriterAttribute.Type, "text")
        output.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
        output.AddAttribute(HtmlTextWriterAttribute.Name, Me.ClientID)
        output.AddAttribute(HtmlTextWriterAttribute.Value, Me.Text)

        output.AddAttribute("OnBlur", "ClientCallback();")
        Me.AddAttributesToRender(output)

        output.RenderBeginTag(HtmlTextWriterTag.Input)
        output.RenderEndTag()

        output.RenderEndTag()
    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        '23-22 Detect Browser
        If (Page.Request.Browser.EcmaScriptVersion.Major > 0) Then

            Page.ClientScript.RegisterClientScriptInclude( _
                "UtilityFunctions", "JScript.js")

            Page.ClientScript.RegisterStartupScript(GetType(Pa ge), _
               "ControlFocus", "document.getElementById('" & Me.ClientID & "').focus();", _
               True)

            Page.ClientScript.RegisterStartupScript( _
                GetType(Page), "ClientCallback", _
                "function ClientCallback() {" & _
                    "args=document.getElementById('" & Me.ClientID & "').value;" & _
                    Page.ClientScript.GetCallbackEventReference(Me, "args", _
                        "CallbackHandler", Nothing, "ErrorHandler", True) + "}", _
                True)
        End If
    End Sub


    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackE vent
        Dim result As Int32
        If (Not Int32.TryParse(eventArgument, result)) Then
            Throw New Exception("The method or operation is not implemented.")
        End If
    End Sub

    Public Function GetCallbackResult() As String Implements ICallbackEventHandler.GetCallbackResult
        Return "Valid Data"
    End Function

End Class


 
Old March 2nd, 2007, 03:04 PM
Registered User
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Finally found it.

the aspx file 'OnClick=' was missing, should be:

<asp:Button ID="Button1" runat="server" Text="Populate" OnClick="Button1_Click" />






Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 23-43 wombel BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 November 30th, 2006 09:40 AM
Chapter 1, Page 23 golden_drifter BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 7 July 9th, 2004 12:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.