Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 November 17th, 2007, 03:55 PM
SV SV is offline
Authorized User
Join Date: Oct 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem getting value out of a custom webcontrol

I have the following web control. When I tab out of the TextBox of this control, I have an alert to display the value of the control. However, when the alert in the ClientCallback() is executed, it displays undefined. This means I some how do not get the control. And suggestions? Looks like there is some problem with the way I am gettting the value out of the control.

Here is the javascript function which gets generated:

function ClientCallback()
 alert(document.getElementById('WebCustomControl1_1 ').value);
 args = document.getElementById('WebCustomControl1_1').val ue;
 WebForm_DoCallback('WebCustomControl1_1',args,Call backHandler,null,ErrorHandler,true)


Here is the code for this control:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebControlLibrary1

    [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : WebControl, ICallbackEventHandler
        public string Text
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);

                ViewState["Text"] = value;


        protected override void RenderContents(HtmlTextWriter output)

            output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            output.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
            output.AddAttribute(HtmlTextWriterAttribute.Name, String.Concat(this.ClientID, "zz"));
            output.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
            output.AddAttribute("OnBlur", "ClientCallback()");



        protected override void OnPreRender(EventArgs e)
            Page.ClientScript.RegisterClientScriptResource(typ eof(WebControlLibrary1.WebCustomControl1), "WebControlLibrary1.Utility.js");

                "function ClientCallback() { alert(document.getElementById('" + this.ClientID + "').value); " +
                "args = document.getElementById('" + this.ClientID + "').value;" +
                Page.ClientScript.GetCallbackEventReference(this, "args", "CallbackHandler", null, "ErrorHandler", true) + "}",

        public void RaiseCallbackEvent(string eventArguments)
            int result;
            if (!Int32.TryParse(eventArguments, out result))
                throw new Exception("The method or operation not implemented");


        public string GetCallbackResult()
            return "Valid Data";

Javascript file:

function ValidateText(ctl)
    if (ctl.value=='') {
        alert('Please enter a value.');

function CallbackHandler(args,ctx)
    alert("The data is valid");

function ErrorHandler(args,ctx)
    alert("Please enter a number");


Similar Threads
Thread Thread Starter Forum Replies Last Post
deploying custom webcontrol pratik28 General .NET 0 June 10th, 2006 01:08 PM
problem applying a style to a webcontrol ACE2084 VS.NET 2002/2003 3 March 10th, 2005 02:10 PM
problem with UI Webcontrol-treeview hawing General .NET 1 December 30th, 2004 11:19 AM
Treeview Webcontrol problem Victor ADO.NET 2 September 9th, 2004 10:55 AM
help in TreeView Webcontrol Victor .NET Web Services 1 September 25th, 2003 06:06 PM

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