Showing posts with label toolkit. Show all posts
Showing posts with label toolkit. Show all posts

Wednesday, March 28, 2012

Programatically accessing Panels and Triggers (In CodeBehind at least)

I have a extensive toolkit that I have written over the past year or two that automatically generates all of my grids, dropdowns, "detail views" and other things. I wanted to start incorporating some snazzy ajax enabled inline calendars and stuff like that. However all of my code is buried deep within class files that generate the controls dynamically. A typical page that has a grid in it is simply a ASP:Placeholder tag, and a snip of codebehind saying what table the user wants to view, and the users group ID (around 3 lines of actual code).

I so to really AJAX enable this I would need a few things to work out, but I don't want to bore you all with those details. I would have tried to do it all of this in my class library already if I could, but when I instantiate a new Trigger, and type "t." to see what options I have, they are only the 4 options that I would have with an variable of type object (Equals, ToString, etc). I cannot even find the "EnablePartialRendering" flag that you need to setup on these panels on the updatepanel obj. Many of these controls have very few if any extra methods/properties/events different from the "System.Web.UI.Control" that they all inherit from.

Am I doing something wrong?

AB

hello.

is this an intellisense problem? if so, have you added the using directive to the source file?


I don't think that there is a problem with the intellisense, I mean, I have been coding for a few years now in .Net, using the intellisense to figure out how things work, without even really bothering with the documentation. It would seem that the Atlas is not to the point where it has the necessary XML markups to the source for the descriptions and what nots to kick in...

Basically, I am looking for examples, given an ASP.Net placeholder, to atlas enable it from the codebehind only, not from the designer... Make sense?

AB

hello again.

let me see if i got this correctly: you want to use the atlas server controls (ex.: UpdatePanel) from your source code files, right?

well, this should work, though i think that the intellisense info is not done yet (ie, you can see the methods/properties, but no info about them). so, your best option is to use .net reflector to see what it does (or, you can allways post your doubts here)


Yes, that is correct.

Have you seen any examples accessing the UpdatePanel from source code? The only examples I have found are in the ASPX Markup files, not the .ASPX.CS codebehind files...

The methods and properties I see are very limited, but as I see it, it would be done like:

Microsoft.Web.UI.ControlEventTrigger t = new Microsoft.Web.UI.ControlEventTrigger();
Microsoft.Web.UI.UpdatePanel up = new Microsoft.Web.UI.UpdatePanel();
up.Controls.Add(SomeLiteralControl);
t.ControlID(SomeButtonControl.ID);
t.EventName("Click");

Now, I can cause "SomeButtonControl" 's click event to change the Literals content and it will ajax that new content into the page?

AB
Ohh yeah, I also don't get the autocomplete for <atlas:UpdatePanel in my ASPX pages, any ideas on that?

AB

hello.

yep, adding triggers should be done like that ( though you still need to add the trigger to the collection maintained by the panel and this should be done until the init event of the page - btw, adding controls to the panel can't be done like that because you need a template).

what problems are you having with the updatepanel?


Hello,

I think I have the same problem. I thought I will start and try to change the example from

http://atlas.asp.net/docs/util/srcview.aspx?path=~/Server/samples/UpdatePanel.src

So the Panel2 is added to PlaceHolder on Page, but the panel doesn't update than.

Any ideas how it should be then, were to initiate the Panel.

For the moment my source code looks like that:

public

partialclassDefault6 : System.Web.UI.Page

{

privateUpdatePanel Panel2;protectedint PostBackCount

{

get

{

return (int)(ViewState["PostBackCount"] ?? 0);

}

set

{

ViewState[

"PostBackCount"] =value;

}

}

protectedoverridevoid OnInit(EventArgs e)

{

this.Init +=new System.EventHandler(this.Page_Init);this.Load +=new System.EventHandler(this.Page_Load);base.OnInit(e);

}

publicvoid Page_Init(Object sender,EventArgs e)

{

Panel2 =

newUpdatePanel();

Panel2.Mode =

UpdatePanelMode.Conditional;

Panel2.ID =

"UPForm";

Panel2.ContentTemplate =

newCTemplate(this);ControlEventTrigger pBtnClikEventTrigger =newControlEventTrigger();

pBtnClikEventTrigger.ControlID =

"Panel3bButton";

pBtnClikEventTrigger.EventName =

"Click";

Panel2.Triggers.Add(pBtnClikEventTrigger);

phPanel2.Controls.Add(Panel2);

}

protectedvoid Page_Load(object sender,EventArgs e)

{

if (IsPostBack)

{

PostBackCount++;

}

}

protectedvoid Panel3aButton_Click(object sender,EventArgs e)

{

Panel2.Update();

}

publicclassCTemplate :ITemplate

{

privateDefault6 m_pInnerControl;public CTemplate(Default6 pInnerControl)

{

m_pInnerControl = pInnerControl;

}

publicvoid InstantiateIn(System.Web.UI.Control container)

{

container.Controls.Add(

newLiteralControl(" [" + m_pInnerControl.PostBackCount +"] "));

}

}

}

thanks a lot in advance

Anna


hello again.

sorry, i didn't look with attention to your code. btw, don't add the panel like that...OnInit is called ot handle the init event, so just call method that adds the panel instead of creating a delegate...i see that you set the trigger to a panel3dbutton...where is this button placed? note that if's inside an user control, you can't do that because you need the full id of the control.


hi,

Thanks for sam clues.

But i noticed that the posted code

upadtes the panel. I changed the line

container.Controls.Add(newLiteralControl(" [" + m_pInnerControl.PostBackCount +" " +DateTime.Now +"] "));

And the date is changed every button click. Only the m_pInnerControl.PostBackCount is always zero.

Anna

Programatically Expand CollapsiblePanel (With Lastest ToolKit)

The issue I am experiencing is due to upgrading to the latest ToolKit. I previously was able to use this code on a postback to expand a collapsible panel.

Previous Code:
Dim clp2 As CollapsiblePanelProperties = CollapsiblePanelExtender2.GetTargetProperties(Panel2)
clp2.ClientState =True
clp2.Collapsed =False

However I do understand that with the upgrade the Properties sections under each of the ToolKit controls is no longer valid. I personally liked the ability to place multiple <atlasToolKit:Properties> tags underneath ONE <atlasToolKit:CollapsiblePanel> tag. Why did you remove that?? It was easy to migrate but a hassle in regards to having to set up a new tag for each time. Anyhow... off of the soapbox.

Current Code:
Dim clp2As CollapsiblePanelExtender = CollapsiblePanelExtender2
clp2.ClientState =True
clp2.Collapsed =False

This fails to expand the Panel on a postback. Any help or solutions?

JoeWeb

I believe the ClientState value needs to be lower cased and quoted as per this post:http://forums.asp.net/thread/1325048.aspx.


Yeah after playing around with it for a little bit... I actually discovered that the following code fixed it.

Dim clp2As CollapsiblePanelExtender = CollapsiblePanelExtender2
clp2.ClientState =False
clp2.Collapsed =False

All that is different is that I set both to false.

Anyhow I figured it out about a week ago sorry I didn't post an update. Thanks!

JoeWeb

Monday, March 26, 2012

Proper documentation on new Ajax installation

A new beginner to Ajax may likely find it a bit difficult to install Ajax control toolkit controls on its toolbox and also the autocompelete extender control and e.t.c. in Microsoft.Web.Preview.dll

I found lots of documentation athttp://ajax.asp.net

You can download the controls and see samples of how to use them. Also in my blog I added links to Scott's doc and samples

Proper way of updating the control toolkit

Hi,

When a new version of the control toolkit is released, what are the proper procedures to replace the new downloaded files with the old ones? Unzip and overwrite all the old files? Then reload the toolbox controls in VS.NET? If that's the case will I have to change anything in my application, whereby the "old" controls are still existent?

Upgrading to a newer Toolkit release


If you were using an older release of the Toolkit and now need to move to a later version here are the recommended steps:

Binaries:Overwrite all old instances of the Toolkit binary "AjaxControlToolkit.dll" on your machine with the new one.Toolbox items:Delete the old tab that listed Toolkit controls and recreate it using the new Toolkit DLL.Toolkit templates:Reinstall the new "AjaxControlExtender.vsi" and check to overwrite the old templates in the "Add Templates" wizard.

Property Page for Controls?

Ok, I may just be a complete idiot, but are there extended property pages available for the controls in the toolkit at design time?

For instance, the PasswordStrength extender has a property calledTextStrengthDescriptions but as far as I can see, it is not on the properties page.

The documentation states it is initialized with this code:

<ajaxToolkit:PasswordStrength ID="PS" runat="server" TargetControlID="TextBox1"DisplayPosition="RightSide"StrengthIndicatorType="Text"PreferredPasswordLength="10"PrefixText="Strength:"TextCssClass="TextIndicator_TextBox1"MinimumNumericCharacters="0"MinimumSymbolCharacters="0"RequiresUpperAndLowerCaseCharacters="false"TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent"TextStrengthDescriptionStyles="cssClass1;cssClass2;cssClass3;cssClass4;cssClass5CalculationWeightings="50;15;15;20" />

But for the life of me, I cannot find this block of code anywhere - so I end up having to set the values in code. Can anyone tell me where the above init code is located or how to access the other non-displayed properties of a control in the designer?

Thanks!

Hi,

Please download the sample applicationhere, then open the PasswordStrength.aspx page, you will find it in the html source.

Property value undefined after succesfull web service call

Hello,

hopefully I can explain my problem.

I started to create extended control with ajax control toolkit. Idea is, that I have textfield which works so

that it suggest values every time when user hits key. Like that --> http://www.google.com/webhp?complete=1&hl=en

Now in SearchTextBoxBehavior.js file I have two propertys, which one hold id for listbox which shows suggestions.
(I think in that google example, the control is span or div element.)


Ok, I have succesfully created event, which is occurred when user hits key in textfield. Webservice call is made in bold code line-->

1_onkeyup : function() {
23 var targetButton = $get(this._TargetButtonID);
4 var targetListBox = $get(this._TargetListBoxID);
5
6if(targetButton && targetListBox) {
7 targetButton.disabled =true;
8
9// unescape() convert′s a string to URL-encoded form10 var searchValue = unescape(this.get_element().value);
11
12if(searchValue !="") {
13// Set suggestion visible14 targetListBox.style.visibility ="visible";
15
16MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded);
17 }
18else {
19// Set suggestion hidden when there is no search value inserted20 targetListBox.style.visibility ="hidden";
21 }
22 }
23
24 },
 
Web service call is succesfull, and returns into function:
 
1_onSucceeded : function(Result) {23var targetListBox = $get(this._TargetListBoxID);45var table = Sys.Preview.Data.DataTable.parseFromJson(Result);67...89}
 
Problem is, that in that _onSucceeded function, propertythis._TargetListBoxID is
undefined. In function, where I made web service call, the property was ok, and I could
make instance about control.
 

Hi,

you need to modify the context under which the callback is executed. This can be done with a delegate and the Function.createDelegate method:

MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,Function.createDelegate(this, this._onSucceeded));



Hi,

it worked, thanks. :)


Yesterday evening I managed to circulate problem, with solution below.

1var inputParams =new Array();2inputParams[0] =this._TargetListBoxID;3inputParams[1] =this._TargetButtonID;4inputParams[2] =this._ListControlTextField;5inputParams[3] =this._ListControlValueField;67MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded,this._onFailed, inputParams);

Hi,

yes, as your code shows, you're passing a context object as the last parameter to the proxy method. This is useful especially if you want to access only certain references in the callback and not the whole instance.


Hi All,

huygens...is there any way you can post your full code? I'm looking to do something similar with the toolkit. Would be greatly appreciated.

Saturday, March 24, 2012

Publishing AtlasControlToolkit "The server block is not well formed"

I just downloaded this toolkit and it worked great. I wanted to publish it on our dev server so I could easily show my co-workers the site.

I got the following error when I tried accessing it,

Parser Error

Description:An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message:The server block is not well formed.

Source Error:

Line 1: <%@dotnet.itags.org. page language="C#" masterpagefile="~/DefaultMaster.master" autoeventwireup="true" inherits="_Default, App_Web_jupskp7v" title="Microsoft "Atlas" Control Toolkit" %>Line 2: Line 3:


Source File:/AtlasControlToolkit/Default.aspx Line:1


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

I edited default.aspx from this,

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title='Microsoft "Atlas" Control Toolkit' %>

to this,

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title='Microsoft Atlas Control Toolkit' %>

I removed the " surrounding Atlas in the title. The site worked fine after this.

Perhaps this should be changed in the toolkit so others do not have the same difficulty.

As I see it, the released sources (/Default.aspx) look like this:

Title='Microsoft "Atlas" Control Toolkit'

Therefore, I suspect that most people will not run into this problem.

Thanks!


That is what mine looked like too.

I published the web site to a dev server here and it resulted in this:

title="Microsoft "Atlas" Control Toolkit"

It worked fine on my local box, just not after I published it. Perhaps it is an issue with the publish feature.


Yes, this appears to be an issue with the publish feature. I tried to work around it by switching to:

Title="Microsoft "Atlas" Control Toolkit"

But publishing again munged it into the same string you had troubles with.

I don't think this is a big deal since the sample site is just for demonstration purposes, but if someone knows a good way to avoid the problem, I'd love to hear it.

Thanks for noting this!


I just switched the quotes around and it solved the problem for me...

Title="Microsoft 'Atlas' Control Toolkit"

Question about AutoComplete textbox

The ASP.NET AJAX Control Toolkit AutoComplete textbox uses a webservice to retrieve a list of suggestions "based on what the user has typed in". I want to create a list of suggestions based on "what the user has typed in" PLUS "the values of some other fields on the form". How can this be done? I don't see a way to access the other field values within the webservice that the AutoComplete textbox uses.

Seems like a reasonable feature request. I have opened work itemhttp://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8414 to track this.

Thanks,

Kirti


Thanks Kirti, that would be great! Is there a temporary workaround I can use? I need to auto complete a textbox for zip codes. The zipcodelist is limited to the country the user selects in a dropdownlist. The the autocomplete webservice should take country as additional parameter.

Question about the ToolKit + Release mode bin

Hi folks,
I'm going to start trying out the Ajax toolkit with VS2008 B2, so i downloaded the ToolKit Framework 3.5 no source zip.

I'm assuming the bin, for the toolkit, is found in the zip file in \SampleWebSite\Bin\AjaxControlToolkit.dll ?
Secondly, i noticed this bin file has a .pdb .. does this mean this dll is NOT optimized for release mode? If I want release mode stuff, do i need to download the other zip (with sources) and compile it myself?

cheers.

Hi,

It's release version. No need to compile the source code again.

Wednesday, March 21, 2012

Question: DynamicServicePath

In trying to troubleshoot my issues with the migration I noted that for the sample ModalPopUp example with the toolkit automatically populates the DynamicServicePath

From the toolkit example (Beta release )

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","CancelControlID":"ctl00_ContentPlaceHolder1_CancelButton","DropShadow":true,"DynamicServicePath":"/test/ModalPopup/ModalPopup.aspx","id":"ctl00_ContentPlaceHolder1_ModalPopupExtender","OkControlID":"ctl00_ContentPlaceHolder1_OkButton","OnOkScript":"onOk()","PopupControlID":"ctl00_ContentPlaceHolder1_Panel1"}, null, null, $get('ctl00_ContentPlaceHolder1_LinkButton1'));
});

In my application - all of my urls are dynamically served... and so for instance for this page url: /localhost/SitesEasyTest/admin/EditNamedPages/default.aspx

The following gets generated:

Sys.Application.add_init(function() {

$create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","DropShadow":true,"DynamicServicePath":"/SitesEasyTest/default.aspx","id":"PopUp","PopupControlID":"ctl00_ctl00_ctl00_PanelModal"}, null, null, $get('ctl00_ctl00_ctl00_Target'));

It is not grabbing the actual url that it should. In the ModalPopUp example and in my own code the DynamicServicePath is not declared it is added by the toolkit at runtime...

I attempted to correct the value via code behind:

MyPopUp = (ModalPopupExtender)GetOptionalControl(skin,"MyPopUp");

MyPopUp.DynamicServicePath = (CommunityGlobals.CalculatePath("Default.aspx")); // properly generates relative path url to the dynamic page

However, the following error is displayed when compiled and tested in a browser:

DynamicControlID must be set

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.ArgumentException: DynamicControlID must be set

[ArgumentException: DynamicControlID must be set] AjaxControlToolkit.DynamicPopulateExtenderControlBase.EnsureValid() +372 AjaxControlToolkit.ExtenderControlBase.GetScriptDescriptors(Control targetControl) +98 Microsoft.Web.UI.ExtenderControl.Microsoft.Web.UI.IExtenderControl.GetScriptDescriptors(Control targetControl) +7 Microsoft.Web.UI.ScriptControlManager.RegisterScriptsForExtenderControls() +187 Microsoft.Web.UI.ScriptManager.OnPreRender(EventArgs e) +402 System.Web.UI.Control.PreRenderRecursiveInternal() +77 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

In either case - the script generated does not generate a DynamicControlID by defaultand so it is puzzling why trying to 'correct' what is incorrect by ovveriding the value - would cause the error?

Does theDynamicServicePath have any purpose if you are not using the dynamic population feature? Otherwise can chalk this up as being a potential issue down the road if I start to use the dynamicservices features...

Thanks!

Relatively easy code fix for the Dynamic Service Path... For sites like mine where I do url rewriting as all content is database driven the following change needs to be applied:

in the ServicePathConverter.cs

namespace AjaxControlToolkit {

publicclassServicePathConverter :StringConverter {

publicoverrideobject ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value,Type destinationType) {

if (destinationType ==typeof(string)) {

string strValue = (string)value;

if (String.IsNullOrEmpty(strValue)) {

HttpContext currentContext =HttpContext.Current;

if (currentContext !=null) {

//OLD

// return currentContext.Request.FilePath;

//Changed by Jody to allow sites that rewrite urls not to

//have paths = /<root>/default.aspx

return currentContext.Request.RawUrl;

}

}

}

returnbase.ConvertTo(context, culture, value, destinationType);

}

}

}

Otherwise, on sites that manage dynamic content and generate urls - the path will always be the root...The filepath works if say you have all 'static' pages in folders etc... but not in dynamically generated scenarios. The code fix will allow for both styles of content to be served properly.