Forum  General Visual ...  How do I...?  How can I use client side scripts
Previous Previous
 
Next Next
New Post 11/28/2008 2:43 AM
  alexgoaga
48 posts
No Ranking


How can I use client side scripts 
Hi,

I have an application which should update a column in a list view with the current time of the system. I want to know if it is possible to move the updating of this column on the client side not on the server how is done right now. Currently, the updating is done using a timer and at every second I update the cell with the current time. The question is how can I update the VWG list view item using client scripts? Also, another scenario: I have some check boxes in a group box and a button, when all the check boxes are unselected the button is disabled but when the user select a check box the button should be enabled. The current implementation has an check changed event for every check box and on the event handler the button is enabled/disabled. The problem is that the check changed event on the check box is very slow on a remote client browser and I want to know if there is a way to make this checking only on the client browser without involving the server.

kind Regards,
Alexandru.
 
New Post 12/1/2008 12:03 AM
  ori.cohen
3523 posts
1st Level Poster




Re: How can I use client side scripts 
Modified By host  on 12/1/2008 4:11:36 AM)
Hello Alexandru!

We currently do not support this type of event handling in any straight-forward way.

As it is very reasonable that we would support this, I opened a new issue on the subject. You can view it here and track our progress.

If you stiil want to go ahead and implement this type of handling please follow the following instructions:

1. Create a new Visual WebGui Control Library. Call it for example "MyLibrary".

2. Add a new VWG CustomControl to the "MyLibrary" project. To see an example how to do that, click here. Call it for example "UserJavaScript". You will use it to contain all the generic control-independant javascript you have. Delete the UserJavaScript.bmp, UserJavaScript.css and UserJavaScript.xslt files.

3. Add to the UserJavaScript.js file all the JS code you have for handling the CheckBox value-changed event to see if all are selected or not. As always the names of the JS functions of CustomControls you create must begin with the name of the CustomControl you created + a '_' character. All commands must end with a ';' character.

4. Add a new VWG CustomControl to the "MyLibrary" project. Call it for example "CheckBoxContainerPanel". You will use it to create a custom Panel that will contain the AllCheckBoxesChecked and NotAllCheckBoxesChecked events. Delete the CheckBoxContainerPanel.bmp, CheckBoxContainerPanel.css, CheckBoxContainerPanel.js and CheckBoxContainerPanel.xslt files. Go to the CheckBoxContainerPanel.cs file and have the CheckBoxContainerPanel class inherit from "Gizmox.WebGUI.Forms.Panel".

5. Add a new VWG CustomControl to the "MyLibrary" project. Call it for example "CustomCheckBox". You will use it to create a custom CheckBox. Delete the CustomCheckBox.bmp, CustomCheckBox.css and CustomCheckBox.js files. Go to the CustomCheckBox.cs file and have the CustomCheckBox class inherit from "Gizmox.WebGUI.Forms.CheckBox".

6. Copy the CheckBox.xslt file's content from the the Gizmox.WebGUI.Forms project in our sources (go to the download page here to get them), into the CustomCheckBox.xslt file. Edit the xslt in this file to add an eventhandler for the event of changing the CheckBox's state to call the JS function "UserJavaScript_AreAllCheckBoxesChecked".

7. Edit the CheckBoxContainerPanel.cs file to override the "FireEvent" method and add the Following code into it:
// Select event type
switch (objEvent.Type)
{
    case "AllCBsChecked":
        OnAllCheckboxesChecked();
        break;

    case "NotAllCBsChecked":
        OnNotAllCheckboxesChecked();
        break;
}
base.FireEvent(objEvent);


8. Edit the CheckBoxContainerPanel.cs file and add the implementation of the OnAllCheckboxesChecked and OnNotAllCheckboxesChecked methods that will fire the relevant event if it has listeners.

9. Edit the UserJavaScript.js file and add the following function "UserJavaScript_AreAllCheckBoxesChecked". Add to this function the logic that you need to see if all CheckBoxes are checked. This can only be done in client-side by checking the nane of the image used in the CheckBox. If not all the CheckBoxes were checked before and now they are, you need to call the following build-in JS function like so:
var objEvent = Events_CreateEvent(strGuid,"AllCBsChecked",null,true);
The strGuid should contain the ID of the
CheckBoxContainerPanel instance that contains the CheckBox that was checked.
If all the CheckBoxes were checked before and now they are not, you need to call the following build-in JS function like so:
var objEvent = Events_CreateEvent(strGuid,"NotAllCBsChecked",null,true);
To send the event to the server, you need to call the following build-in JS function:
Events_RaiseEvents();

10. Set the
UserJavaScript.js and CustomCheckBox.xslt files to be "Embedded Resource" and "Do not copy".

11. Register all three CustomControls in our application's Web.config "Controls" section, with the "MyLibrary" namespace and assembly name.

Regards,

Ori Cohen
The Visual WebGui team
 
New Post 12/1/2008 12:11 AM
  alexgoaga
48 posts
No Ranking


Re: How can I use client side scripts 
Hi,

Thanks for the quick answer.

Kind Regards,
Alexandru.
 
New Post 12/1/2008 12:15 AM
  ori.cohen
3523 posts
1st Level Poster




Re: How can I use client side scripts 
Hello Alexandru!

No problem.
I corrected a few things in my post. Please view again.

Regards,

Ori Cohen
The Visual WebGui team
 
New Post 12/26/2008 3:32 PM
  fra_gar
1 posts
No Ranking


Re: How can I use client side scripts 

I tried to implements a client-side function, but I can't achieve. I'm not a guru programmer, but I'm trying to migrate to VWG framework. I would like to implement the logic with treeview control, when a user click on a parent node all child become checked. If at least one child node is check, then the parent must be checked.  I already achieve this using asp.net treeview control and usign a JavaScript function, because I want to void the server round trip.   Using the steps posted by Ori,I tried to do it, buy I couldn't, I did this:

 

1. I create a .js file

// JScript source code for tvJavaScript control

// <script language="javascript" type="text/javascript">

//************************** Treeview Parent-Child check behaviour ****************************//

function

tvJavaScript_OnTreeClick(evt) {var src = window.event != window.undefined ? window.event.srcElement : evt.target;var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");if (isChkBoxClick) {var parentTable = tvJavaScript_GetParentByTagName("table", src);var nxtSibling = parentTable.nextSibling;if (nxtSibling && nxtSibling.nodeType == 1)//check if nxt sibling is not null & is an element node

{

 

if (nxtSibling.tagName.toLowerCase() == "div") //if node has children

{

 

//check or uncheck children at all levels

tvJavaScript_CheckUncheckChildren(parentTable.nextSibling, src.checked);

}

}

 

//check or uncheck parents at all levels

tvJavaScript_CheckUncheckParents(src, src.checked);

}

}

 

function

 

 

 

childChkBoxes[i].checked = check;

}

}

tvJavaScript_CheckUncheckChildren(childContainer, check) {var childChkBoxes = childContainer.getElementsByTagName("input");var childChkBoxCount = childChkBoxes.length;for (var i = 0; i < childChkBoxCount; i++) {

function

 

 

 

 

 

tvJavaScript_CheckUncheckParents(srcChild, check) {var parentDiv = tvJavaScript_GetParentByTagName("div", srcChild);var parentNodeTable = parentDiv.previousSibling;if (parentNodeTable) {var checkUncheckSwitch;if (check) //checkbox checked

{

 

// Seccion original, que check el padre si todos los hijos estan

 

// seleccionados unicamente, en mi caso yo deseaba

 

// checkear el padre si al menos un hijo estaba chequedado

 

// var isAllSiblingsChecked = AreAllSiblingsChecked(srcChild);

 

//if(isAllSiblingsChecked)

 

// checkUncheckSwitch = true;

 

// else

 

// return; //do not need to check parent if any (one or more) child not checked

 

 

checkUncheckSwitch =

 

var isASiblingsChecked = tvJavaScript_AreASiblingChecked(srcChild)if (isASiblingsChecked)true;else

 

}

 

return;else //checkbox unchecked

{

 

// linea siguiente era la unica originalmente

 

// checkUncheckSwitch = false;

 

 

checkUncheckSwitch =

 

var isASiblingsChecked = tvJavaScript_AreASiblingChecked(srcChild)if (isASiblingsChecked)true;else

checkUncheckSwitch =

}

 

 

 

parentNodeChkBox.checked = checkUncheckSwitch;

 

false;var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");if (inpElemsInParentTable.length > 0) {var parentNodeChkBox = inpElemsInParentTable[0];//do the same recursively

tvJavaScript_CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);

}

}

}

function

 

 

 

 

tvJavaScript_AreAllSiblingsChecked(chkBox) {var parentDiv = tvJavaScript_GetParentByTagName("div", chkBox);var childCount = parentDiv.childNodes.length;for (var i = 0; i < childCount; i++) {if (parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node

{

 

 

 

if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];//if any of sibling nodes are not checked, return false

 

 

}

}

}

}

 

}

if (!prevChkBox.checked) {return false;return true;

function

 

 

 

 

tvJavaScript_AreASiblingChecked(chkBox) {var parentDiv = tvJavaScript_GetParentByTagName("div", chkBox);var childCount = parentDiv.childNodes.length;for (var i = 0; i < childCount; i++) {if (parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node

{

 

 

 

if (parentDiv.childNodes[i].tagName.toLowerCase() == "table") {var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];//if any of sibling nodes are not checked, return false

 

 

}

}

}

}

 

}

if (prevChkBox.checked) {return true;return false;

//utility function to get the container of an element by tagname

function

 

 

parent = parent.parentNode;

}

 

}

tvJavaScript_GetParentByTagName(parentTagName, childElementObj) {var parent = childElementObj.parentNode;while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {return parent;

///////////////////////////////////////////////////////////////////////////////////////

// </script>

 

 

2. I create a CustomTreeView  (only the .cs and the .xslt files), and I copied the content of TreeView.xslt to my CustomTreeView.xslt file, and I tried to add my event handler like this:

<

<

<

<

<

</

<

<

</

</

</

</

xsl:if test="$prmCheckBoxes and @Attr.CheckBoxes='1'">td class="TreeView-CheckBox" onclick="mobjApp.Events_FireEvent({@Id},'tvJavaScript_OnTreeClick',true)" >xsl:choose>xsl:when test="@Attr.Checked='1'" >img src="Skins.CheckBox1.gif.wgx" style="margin-{$right}:2px"/>xsl:when>xsl:otherwise>img src="Skins.CheckBox0.gif.wgx" style="margin-{$right}:2px"/>xsl:otherwise>xsl:choose>td>xsl:if>

 

3. I've created a Container Panel, my file is named tvContainerPanel (I have only th tvContainerPanel.cs), and I added the following code:

protected

{

 

override void FireEvent(IEvent objEvent)//If the control is hidden or disabled

 

//don't fire it's events

 

{

 

{

 

OnTreeClick();

 

 

if (this.Visible && this.Enabled)switch (objEvent.Type)case "tvJavaScript_OnTreeClick":break;//default:

 

// base.FireEvent(objEvent);

 

// break;

}

 

}

}

base.FireEvent(objEvent);

 

 . . . . .   and I'm here, I can't figure out how do it . . . ., I just want call the JavaScript function tvJavaScript_OnTreeClick from the client side, this function call the others JavaScripts functions that help me to achieve what I described at the beginning.  I would appreciate any help.

 

 

 

 

 

 

 

 

 

 
Previous Previous
 
Next Next
  Forum  General Visual ...  How do I...?  How can I use client side scripts
Most promising startups
Top 3 most promising startups in 2009
   AJAX Framework | Web Development | Cloud applications | RIA Development | Silverlight Applications | Legacy Migration
The most popular open source Ajax applications framework for enterprises | Sitemap | Terms Of Use | Privacy Statement
Copyright © 2005-2009 Visual WebGui®    Design By: Template World
   
Visual Studio Partners