Update: The javascript on this blog has been suppressed by the blogger's parser. Consequently, some of the functionality may not work. Inconvenience is regretted.

Tuesday, May 20, 2008

Leveraging Asp.Net WebForms Client Library

While working with asp.net, most front end developers have their own javascript library of utility functions like: (get/set)ElementPosition, getScroll(x/y), (add/remove)ClassName, etc. Most of the times there is no need to have your own versions of some of the more commonly used javascript utility functions as they are already present in the Webresourse.axd javascript file embedded (not always) in your asp.net page and most importantly the functions are Cross Browser. The utility functions in this client library are used for asp.net callbacks & postbacks, in addition to being used by asp.net validation, treeview and menu client libraries (yes, there are seperate libraries for all these). So, if you are using asp.net menu/treeview/validators/callbacks on your webpage, you can happily use the functions provided in the library. If you want to ensure that the library is included in your page, just use a nice to have feature in your asp.net page: MaintainScrollPositionOnPostback:

<%@ Page Language="C#" MaintainScrollPositionOnPostBack="true"
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



or appliying it sitewide thru web.config as:



<system.web>
<pages maintainScrollPositionOnPostBack="true">
</pages>
</system.web>




The script file is included in my page as:

<script type="text/javascript" src="/TestWebsite/WebResource.axd?d=X2ApKqYNd-qiVRFcah5bwg2&t=633437918395970000">

Following is the list of some of the commonly used functions present in the library:



    WebForm_GetScrollX

    WebForm_GetScrollY

    WebForm_SetElementX

    WebForm_SetElementY

    WebForm_GetElementById

    WebForm_SetElementWidth

    WebForm_SetElementHeight

    WebForm_RemoveClassName

    WebForm_AppendToClassName

    WebForm_GetParentByTagName

    WebForm_GetElementByTagName

    WebForm_GetElementsByTagName

    WebForm_GetElementPosition - another version here


Hope this is helpful.


pushp

2 comments:

Taxanomy said...

Hi Push,
Mahender here..Godd article dude ..

Anonymous said...

Home page --> Click on the Link (Opens the second Window)

the below scenario on the second window

I have 7 controls on my second page.

First control : Task Origin (Combo Box)
Second Control: Task Category (Combo Box)
Third Control: Task Type (Text field)


Based on the Task Origin selection Task category combo is filled.
Based on the Task Category selection Task type is derived

After entering the correct value in the Task Type filed (By pressing the TAB) its validate the entry in text field and fill the other 4 fields.

I am able to select the value from Task Category and Task Origin but when I type the value for Task type field it’s not deriving the value for other field.


Console.WriteLine("Task Management Page...");
Static_Decl.i.Span(Find.ById("_ctl0_MainContentPlaceHolder_TaskManagementIndex_CreatePanel_lblPanelHdr")).Click();
//Static_Decl.i.WaitForComplete(10000);
var findby = Find.ByTitle("Create Task");
var TaskCreatePage = Browser.AttachTo(Static_Decl.i.GetType(), findby);
//Task Origin
TaskCreatePage.SelectList("_ctl0_MainContentPlaceHolder_wd_wdDdlTaskOrigin").Click();
TaskCreatePage.SelectList(Find.ById("_ctl0_MainContentPlaceHolder_wd_wdDdlTaskOrigin")).Option(Find.ByValue("TFAUTO")).Select();

// Task Category
TaskCreatePage.SelectList("_ctl0_MainContentPlaceHolder_wd_wdLstBoxCategory").Click();
TaskCreatePage.SelectList("_ctl0_MainContentPlaceHolder_wd_wdLstBoxCategory").Option(Find.ByValue("A")).Select();

// Task Type
TaskCreatePage.TextField(Find.ById("_ctl0_MainContentPlaceHolder_wd_wdLstBoxType")).Click();
TaskCreatePage.TextField(Find.ById("_ctl0_MainContentPlaceHolder_wd_wdLstBoxType")).TypeText("TFA");
TaskCreatePage.TextField(Find.ByName("_ctl0:MainContentPlaceHolder:wd:wdLblWorkIdTxt")).Focus();

Can you help me to overcome this issue?