CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Working With Component Attributes

This example demonstrates how to dynamically set value of a component attribute, in this case disabling textbox when users view their profile.
Let's assume that we have a TextBox named user_login, located in Registration form. The event code disables the textbox if the URL contains mode=profile.

  1. While in the HTML mode use the context menu to insert {user_login:disabled} attribute into TextBox template. The HTML should  look as follows:
    <input name="{user_login_Name}" value="{user_login}" {user_login:disabled}>
  2. Add 'Custom Code' action to the Before Show event of the TextBox.
  3. Use the code shown below within the action body:

ASP

   If CCGetFromGet("mode", "") = "profile" Then  _
      Sender.Attributes("disabled") = "disabled"

PHP

  if (CCGetParam('mode', '') == 'profile') {
    $Component->Attributes->SetValue('disabled', 'disabled');
  }

Perl

  if (CCGetFromGet('mode', '') eq 'profile') {
    $Component->{Attributes}->SetValue('disabled', 'disabled');
  }

ColdFusion

  <CFPARAM Name="URL.mode" Default="">
  <CFIF URL.mode EQ "profile">
    <CFSET StructInsert(attrUser_login, "disabled", "disabled", True)>
  </CFIF>

VB.Net

  If Request.QueryString("mode") = "profile" Then
    ControlAttributes.Add(usersuser_login, New CCSControlAttribute("disabled", FieldType._Text, "true"))
  End If

C#

  if (Request.QueryString["mode"] == "profile") {
  	ControlAttributes.Add(usersuser_login, new CCSControlAttribute("disabled", FieldType.Text, "true"));
  }

Java

  if ("profile".equals(e.getPage().getHttpGetParams().getParameter("mode"))) {
	((com.codecharge.util.ModelAttribute)e.getModel().getAttribute("disabled")).setValue("disabled");
  }

See Also:


On-line, printable versions and updates