Showing posts with label ive. Show all posts
Showing posts with label ive. Show all posts

Wednesday, March 28, 2012

Extenders in Composite/Custom Controls

I've created composite or custom controls with ajaxcontrol extenders, example is a textbox with FilteredTextBoxExtender. So far I am able to make the new control work.

My problem is how to expose the extender's properties that are of enumeration type like the FilterType where you can assign more than one value in comma delimited format (ex. "Number, Custom" or "UppercaseLetters, Custom")

I think it is not possible to directly access the childcontrol's (the extender) properties from the class, so how do I create a property that do the same as the extender's property?

I looked into the code of the AjaxControlToolkit, in C# its

[ExtenderControlProperty]

[DefaultValue(FilterTypes.Custom)]

publicFilterTypes FilterType

{

get {return GetPropertyValue<FilterTypes>("FilterType",FilterTypes.Custom); }set { SetPropertyValue<FilterTypes>("FilterType",value); }

}

I need a code for vb.net, I also tried converting the code using some online conversion tool but the result is not working. Here's the result:

<ExtenderControlProperty()> _

<DefaultValue(FilterTypes.[Custom])> _

PublicProperty FilterType()As FilterTypes

Get

Return GetPropertyValue(Of FilterTypes)("FilterType", FilterTypes.[Custom])

EndGet

Set(ByVal valueAs FilterTypes)

SetPropertyValue(Of FilterTypes)("FilterType", value)

EndSet

EndProperty

----

Any help is appreciated.

Solved.

Sometimes you just need to take a break to clear your mind. I was making my code complicated. :)

Monday, March 26, 2012

Exposing methods in ASP.NET AJAX Control Project

I've read every bit of documentation that I could find online (which isn't a lot) about creating your own extender with the ASP.NET AJAX Control Project. There are lots of examples about how you expose the properties in the Extender.vb or Extender.cs file, which passes the values down to the .js file. But is it possible to expose callable methods? I can add handlers forevents, but what about methods you can call at any time?

If anyone can give me an example of the proper syntax to do this, it would be greatly appreciated. Thanks.

You can't expose methods from the .cs or .vb file of your control; you'll need to use webservices or pagemethods to call a server method.

I don't want to call a server method, I want to expose a function in the Behavior.js.


Do you mean callable by JavaScript or Server-Side Code ?

all methods in your behavior.js in the Prototype section are callable methods.

You can call methods using the

$find(BehaviorID).Method() notation


Thank you for the response. That's what I needed, but just out of curiosity, is it possible to "expose" those methods to the servers side... much in the same way that the properties in the extender.cs file exposes the properties in the behavior.js file?


No.

The properties in the .cs file will be injected into the output html, and some initialization logic implemented in javascript is responsible for initializing the component with those properties.

Basically, server side object and client side object can't access each other directly.

Saturday, March 24, 2012

Example of using ControlBase class

As I've learened from ASP.NET AJAX IN ACTION AJAX toolkit also allow as to create Script Controls (AJAX Extension) with ControlaBase class (Extenders are inherited from ExtenderBase). Why ajax toolkit provide only extender template? Have anybody used ControlBase class?

Hi,

Which ControlBase class are you referring to? There is only a ExtenderControlBase class that acts as the base class.

The main purpose of the template is to provide a better starting point for creating an Extender, some necessary logics has been added in the base class. Of course, you may choose a different base class, event Control class. But developers will have to do more in this case, and it's more error-prone.


Raymond Wen - MSFT:

Which ControlBase class are you referring to?

On the server side, the Ajax Control Toolkit defines two base classes: ExtenderControlBase and ScriptControlBase. The ExtenderControlBase class derives from the ExtenderControl class and is used to create extenders. The ScriptControlBase class inherits from the ScriptControl class and is used to create script controls.

On the client side, the Microsoft Ajax Library provides the Sys.UI.Behavior and Sys.UI.Control classes for creating visual components. In turn, the Toolkit API provides base classes that encapsulate additional functionality for creating behaviors and controls. These classes are called BehaviorBase and ControlBase.

These are two quotations from Manning ASP.NET AJAX IN ACTION

Wednesday, March 21, 2012

Event Triggered from UpdatePanel1 fires validator in UpdatePanel2

I have a form with requiredfieldvalidators inside separate updatepanels, whose UpdateMode's are set to conditional. I've set timestamps in each panel to ensure that the updatemode was functioning correctly, which it is. However, it seems that a postback triggered in the first update panel still fires my validator in my 2nd update panel. I've attached code below. Your insight is much appreciated!

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Update Panel Test</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> This is Panel 1. <div> TextBox1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="TextBox1 isn't filled in."></asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Button1" /><%=DateTime.Now%> </div> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server"> <ContentTemplate> This is Panel 2. <div>Textbox2: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="TextBox2 isn't filled in."></asp:RequiredFieldValidator> <asp:Button ID="Button2" runat="server" Text="Button2" /><%=DateTime.Now%> </div> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

You just need to assign the two sets of controls to different validation groups.

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ... ValidationGroup="Grp1" />
<asp:Button ID="Button1" ... ValidationGroup="Grp1" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ... ValidationGroup="Grp2" />
<asp:Button ID="Button2" ... ValidationGroup="Grp2" />

Also, you don't need UpdatePanels to make this work.


Assign each button a different validator that will solve the issue

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Update Panel Test</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Auto">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
This is Panel 1.
<div>
TextBox1:<asp:TextBox ValidationGroup="panel1" ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="panel1" ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="TextBox1 isn't filled in."></asp:RequiredFieldValidator>
<% =DateTime.Now %>
<asp:Button ID="Button1" ValidationGroup="panel1" runat="server" Text="Button1" />
</div>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
This is Panel 2.
<div>
Textbox2:
<asp:TextBox ID="TextBox2" ValidationGroup="panel2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="panel2" ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="TextBox2 isn't filled in."></asp:RequiredFieldValidator>
<% =DateTime.Now %>
<asp:Button ID="Button2" ValidationGroup="panel2" runat="server" Text="Button2" />
</div>
</ContentTemplate>
</asp:UpdatePanel
</div>
</form>
</body>
</html

Event fire only once !

Hi,

I've got a little problem ^^. I'm using an update panel wich is created dynamically.

The control inside the updatepanel make some postback calling the __doPostBack function created using the GetPostBackEventReference function.

First time i click on one of the item that is inside the update panel it send an asynchronous request, the controls inside the update panel are created, then

the function that handle the postback event is called, it deletes one of the item inside the update panel and refresh the content of the update panel (you might notice that the update panel is first filled to recreate the control that handle the event, then it deletes the item from the database, then it recreates all the item inside the updatepanel).

The problem is that after this asyncronous callback, if i try to click on another item the asynchronous callback is done but the event handling function is not called :s ... then i retry to click and it works, the event handler is called ...

So i think that the problem is more an asp .net problem, maybe due to the page life cycle, but if someone could show me the light or a way to find the light it would be create :)

Thanks

http://news.infragistics.com/readmessage?id=%3C2c08997$32849066$2c1d78@.news.infragistics.com%3E&group=infragistics.products.netadvantage.aspnet.webasyncrefreshpanel


set "_spFormOnSubmitCalled = false: "_spFormOnSubmitCalled" object, as mentioned, is given in C:\Program
Files\Common Files\Microsoft Shared\web server extensions\12
\TEMPLATE\LAYOUTS\1033\Init.js
function _spFormOnSubmitWrapper()
{
if (_spSuppressFormOnSubmitWrapper)
{
returntrue;
}
if (_spFormOnSubmitCalled)
{
returnfalse;
}
if (typeof(_spFormOnSubmit)=="function")
{
var retval=_spFormOnSubmit();
var testval=false;
if (typeof(retval)==typeof(testval) && retval==testval)
{
returnfalse;
}
}
RestoreToOriginalFormAction();
///_spFormOnSubmitCalled=true;
_spFormOnSubmitCalled=false; // !!!!!!!!!
returntrue;
}

Errors in web.config when creating AJAX-type projects

Hi,

Whenever I create a AJAX website, or AJAX Control toolkit website, errors are found in my web.config, even before I've done anything

Warning 1 The 'requirePermission' attribute is not declared. C:\Documents and Settings\Louis\My Documents\Visual Studio 2005\WebSites\AJAXEnabledWebSite1\Web.config 6 213 C:\...\AJAXEnabledWebSite1\
Warning 2 The 'requirePermission' attribute is not declared. C:\Documents and Settings\Louis\My Documents\Visual Studio 2005\WebSites\AJAXEnabledWebSite1\Web.config 8 205 C:\...\AJAXEnabledWebSite1\
Warning 3 The 'requirePermission' attribute is not declared. C:\Documents and Settings\Louis\My Documents\Visual Studio 2005\WebSites\AJAXEnabledWebSite1\Web.config 9 199 C:\...\AJAXEnabledWebSite1\
Warning 4 The 'requirePermission' attribute is not declared. C:\Documents and Settings\Louis\My Documents\Visual Studio 2005\WebSites\AJAXEnabledWebSite1\Web.config 10 213 C:\...\AJAXEnabledWebSite1\

Any ideas?

bump anyone?

EDIT: Also, I noticed intellisense seems to be broken, in the sense I only get "!--, ![CDATA[]], ?" when I type "<"


Ok, installing SP1 kinda solved it.