Showing posts with label ModalPopupExtender. Show all posts
Showing posts with label ModalPopupExtender. Show all posts

Wednesday, June 12, 2013

Search and replace using PowerShell

 

Last week we were faced to a problem: there are numerous files distributed in hierarchy of folders on the disk and we are required to replace a pattern string in each of these files to a specified replacement string. (In fact, we had to add quickly hardwired location parameters to all the AJAX ModalPopupExtender controls in an ASP.NET solution).

The challenge is: the files cannot be copied outside of the target machine, processed and copied back – all the processing MUST occur on the target box using only on-board tools. And there aren’t any built-in software in Windows (Server 2008 R2) providing such functionality like S&R, Visual Studio or other similar tools, enabling recursive search and replace operations.

Some of us started to wipe dust off their DOS command line skills and write some batch files. But the better solution is in use of built-in PowerShell.

Start PowerShell and launch following command:

dir –r {fileseach pattern}| %{ $x = get-content $_ ; $x = $x -replace ({search pattern}, {replacement pattern}) ; set-content $_ $x }

For example:

dir -r *.aspx| %{ $x = get-content $_ ; $x = $x -replace ("ModalPopupExtender ID", "ModalPopupExtender X=""100"" Y=""100"" ID") ; set-content $_ $x }

replaces string

ModalPopupExtender ID

with

ModalPopupExtender X="100" Y="100" ID

in all .aspx files in current folder and below

This makes from

<ajax:ModalPopupExtender ID=”mpe1” …/>

the string

<ajax:ModalPopupExtender X="100" Y="100" ID=”mpe1” …/>

So all the processing occurred on the target box without any need to copy the files to equipped machine, process them and copy back. Also without any need to install/deploy additional software to the target machine specially to perform desired processing.

Next time you need to replace some string with another one in a number of files distributed in recursive subfolders using only built-in software of Windows OS – do not panic: use pattern PowerShell command from above and enjoy!

Thursday, March 03, 2011

ASP.NET & AJAX: “Object required” Script error while using ModalPopupExtender

Loading an ASP.NET Webpage containing ModalPopupExtender you may encounter following error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Timestamp: Thu, 3 Mar 2011 07:21:58 UTC


Message: Object required
Line: 106
Char: 13
Code: 0
URI:
http://localhost:49461/ScriptResource.axd?d=dVTmaeP-mJEQBF1x5WPACI57lI3BdxWWqqcjOSvk5IFYlzy3XmoJ3-mETMUX_E93dUXCirqabEt7Y5F8nk9OJF0v1sSq6MFJL4n1ystjZ74KXzsw7JAw7fRseSEZ165rrnTm4dOfgdUE7UZpQUpfBqdlctB5nzYxeqQR46Jg_TR_hyK50&t=ffffffffa4fab0f1

image

Start debugger, and you will learn more:

image

this._popupElement = $get(this._PopupControlID);
if (this._DropShadow) {
this._foregroundElement = document.createElement('div');
this._foregroundElement.id = this.get_id() + '_foregroundElement';
this._popupElement.parentNode.appendChild(this._foregroundElement);
this._foregroundElement.appendChild(this._popupElement);
}
else {
this._foregroundElement = this._popupElement;
}


The cause of this error is most likely the Panel used as TargetControl for ModulPopupExtender. Check if this Panel not set accidentally to



Visible="false"


In this case ASP.NET doesn’t render this panel at all, and the _PopupControlID property of the popup extender on the client side points to non existent object.


Check the Visible attribute of the popup panel, reset it to visible and enjoy!