Gonzo TechNet
How to dynamically change the text in an ASP.NET (3.5) panel/div?

You created a "panel" (ie: <div>) and want to set or change the text within it using VB.NET (Visual Basic), but, there is no "text" property or method....What gives?


The trick is that you need to create a reference to the panel object as a "LiteralControl" and then set its "text" property.

  1. In the page designer, add a "panel" and give it an id of "pnlText"
  2. In the code-behind file, create a reference variable of type "LiteralControl" (A "reference" is a uninitialized typed variable.)
  3. Set the oPanel reference to the first internal control of the pnlText object, casting the pnlText object to the "LiteralControl" object. By "casting" the pnlText object to specific object type (ie: LiteralControl), it then inherits the properties and methods of that object.
  4. Now you can set the text property using VB in the code-behind page. Here's the full code in one shot:

Dim oPanel as LiteralControl
oPanel = CType(pnlText.Controls.Item(0),LiteralControl)
oPanel.text = "Hello Internet!"
Object conversion error using ASP.NET AJAX to retrieve data from a WebService/WebMethod
When you make a call to a WebService/WebMethod you recieve an error message similar to one of the following:
	"Cannot convert object of type 'System.String' to type 'System.String&'"
	"Cannot convert object of type 'System.String' to type 'System.Int32&'"

The key to decoding the source of this message is the "&" located in the end of the text. This is the syntax used when passing a parameter to a function BYREF (By-Reference). Note: This is the syntax used in C-Notation to indicate "pass the AddressOf" varname. Even if you coded the WebService in VB.NET, Microsoft will convert/compile it in C type notation when it outputs it as an assembly.

The problem/solution is that all parameter definitions for your WebMethod must passed BYVAL (By-VALUE). Check the procedure/webmethod definition for your WebSerice. It is probably has a paramater defined (incorrectly) as (ByRef pname as xxx).

How to get the #ID of an ASP.NET control using JavaScript

When you add a control to an ASP.NET page using Visual Studio [Express] 2008 and give it an ID, this may NOT be the ID that appears in the HTML markup when the page is actually rendered.

Example: You add the following textbox control to a form.
<asp:TextBox ID="txtemail" runat="server" MaxLength="320" Width="20em"><asp:TextBox>

However, when you run the page and look at the HTML markup/source in your browser, you find that the "#ID" of the control is NOT "txtemail". This is because Microsoft generates an #ID/name based on the ID you provide to the designer/IDE when it renders the page.

Because the VS 2008 may change the #ID of the control during page generation, attempting to reference or get a handle to the control using JavaScript and the control's "supposed" #ID of 'txtemail' may fail. The following MAY fail:

if document.getElementById("txtName").value == "some text" {

The trick is to force ASP.NET to substitute the actual #ID that the server generates to your JavaScript Code. You do this by using ASP.NET/VB.NET variable substitution to supply the "ClientID" of the control/element during page generation by the server. Use the following sytax in your javascript code:

if document.getElementById("<=txtName.ClientID%>").value == "some text" {
How to add your own JavaScript validation functions to an ASP.NET page that contains validation controls

This one ANNOYED me for the better part of a day! I had a simple login form with some asp:input (textbox) fields, and a couple of HoneyPot/Captcha fields to prevent BOTS/Spammers from submitting the form. Also on the form was a simple INPUT/SUBMIT button.

Some requiredfield validators were added to the page to force the user to enter thier login/password. Everything worked fine until I added my own JavaScript function to the "onclick" event of the submit button, intended to the validte HoneyPot/Captcha fields and prevent the form from being submitted if the fields were changed.

No matter how I adjusted the rfv's or the code in my validatePage() function, nothing worked right and the page constantly did a PostBack.


Force the MS client-side validation routines to run FIRST from within YOUR JavaScript/Validation function.

MY validation function is called: validateForm()  To my submit button I added: onclick="return validateForm();"

In the code of my validateForm() function I added the following: (and everything ran fine...)

function validateForm() {

//Check the MS validations first!
if (Page_ClientValidate() == true) {

.... (run my code)
return false;    //to prevent the page from being submitted }


Home | TechNet | ADO.Net | DOS | ASP.NET | IIS | VB.NET | VIM (vi) | Windows | XHtml
MS-SQL | T-SQL | SSIS | Oracle