Showing posts with label extender. Show all posts
Showing posts with label extender. Show all posts

Wednesday, March 28, 2012

Disable Autocomplete extender in code

Is there any way to disable an autocompleteextender?

I have an autocompleteextender that works fine with a textbox but I need to hide that textbox. When I hide it, a javascript exception is thrown because the atlas code can't find the control. What should I do to disable the autocompleteextender in code?

Thanks

I was using this code:

foreach

(AutoCompleteProperties propin AutoCompleteExtender1.TargetProperties) {

prop.Enabled =

false;

}

But it didn't work. However with this it works:

AutoCompleteExtender1.TargetProperties.Clear();

Probably there's a bug somewhere because I think what I was doing should be enough.


hello.

how are you hiding the textbox? i'm guessing that you're setting the visible property to false...unfortunatelly, it looks like the xml script willnot be rendered itht ie enabled property is set to false. you can try to set both the visible and enabled properties of the associated textbox controls to false and this should stop the generation of the xml-script...


It is inside a table row so I set the table row to runat=server and set visible = false to the table row.

I have just tried setting the textbox enable and visible properties to false but it still doesn't work. I think that the correct behaviour should be not to render the xml-script related to the autocomplete textbox when the associated TargetProperty is not enabled.


hello again.

hum...after looking at what's going on, i think that the problem is that the behavior is being registered even when the control is not visible. you can change this by building your own completeextender with code similar to this one:

namespace

LA

{

publicclassBetterAutoCompleteExtender :AutoCompleteExtender

{

protectedoverridevoid OnPreRender(EventArgs e)

{

WebControl ctl =this.NamingContainer.FindControl(this.TargetProperties[0].TargetControlID)asWebControl;if ( ctl !=null && ctl.Visible &&this.TargetProperties[0].Enabled )

{

base.OnPreRender(e);

}

}

}

}

hope this helps (btw, you should open a bug report by adding a new post to the forum and redirect them to this post to get more info about the problem - don't forget to add the [BUG] word on the title).


Thanks Luis.

With that it works properly.

I'll add a new post with the bug.


Hello,

I'm attempting to put the autocomplete extender in a tabbed form. Is there a way to disable the autocomplete when the style of the div layer that the textbox is in gets set to style="display:none"?

Thanks,
Emilie

hello.

hum...in your scenario, you shouldn't need to disable it because if you're setting the display style, that means that all the elements will be loaded and you won't get errors when searching for them...


Here's the simple sample I'm working with:

<body>
<form id="Form1" runat="server">
<atlas:ScriptManager id="AtlasPage1" runat="server" />

<div style="display:none">
<asp:TextBox ID="TextBox1" runat="server"/>
</div>

<Atlas:AutoCompleteExtender runat="server" ID="autoComplete2">
<Atlas:AutoCompleteProperties TargetControlID="TextBox1"
Enabled="True" ServicePath="AutoCompleteService.asmx"
ServiceMethod="GetWordList"
minimumprefixlength="1" />
</Atlas:AutoCompleteExtender>
</form>
</body
Right now it gives me an "invalid argument" exception and cannot find the source code to break to.
However, if I remove style="display:none" from the div, it works fine.
I ran it again this morning and this time it was able to break to the line of code that was failing. In the Webresource.axd file there's a line

completionListStyle.width = (elementBounds.width - 2) + 'px';

But when the div is set to display:none, elementBound.width (referring to the width of the textbox) is 0.

Anyone have ideas on how to get around this?
I'm having the same problem here: when display: none is set, the autocompleteextender throws up an error.

Is there a workaround for this yet?

any news on this one, I have the same problem?

Andy

dinamically adding a webuser control to a Modal Pop Up Extender

I have a page that has two buttons and a text box on it. It also has a panel named pnlPopUp and an modalpopupextender which has 'pnlPopUp' as the PopupControlID.

If you Click Button1 it will display webusercontrol1 and if you click button2 it will display webusercontrol2.

Each user control has two buttons on tem (btnOK and btnCancel).

The web user controls are added dinamically to the panel when I click button1 or button2 (using Page.LoadControl("~/WebUserControl.ascx") andpnlPopup.Controls.Add(webusercontrol) );

I am trying to fill the text of teh textbox in the page according to which button is clicked on the pop-up (if I click Ok it writes "OK" in the textbox),

but my button events aren′t firing!


P.S.: If I load the controls in the page′s Page_Load and making them visible when I need them it will work fine but I didn′t want to do that because in my actual web site i will have too many user controls.

Here′s the sample code. (I′m using the exact code for both user controls):

==================== Default.aspx=============================

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register src="http://pics.10026.com/?src=~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="wuc" %
<!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 runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" href="http://links.10026.com/?link=back.css" type="text/css" media="screen" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="btnPopup" runat="server" Text="PopUp" />

<input type="hidden" runat="server" id="hdnPopUp" />

<asp:Panel ID="pnlPopUp" runat="server" CssClass="modalPopup">
</asp:Panel>

<cc1:ModalPopupExtender ID="mpeTestePopUp" runat="server" TargetControlID="hdnPopUp"
PopupControlID="pnlPopUp" DropShadow="true" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

===========================================================

==================== Default.aspx.cs============================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

public partial class _Default : System.Web.UI.Page
{
WebUserControl ucTestePopUp;

protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnPopup.Click += new EventHandler(btnPopup_Click);
}

void btnPopup_Click(object sender, EventArgs e)
{
ucTestePopUp = (WebUserControl)Page.LoadControl("~/WebUserControl.ascx");
this.pnlPopUp.Controls.Add(ucTestePopUp);
this.mpeTestePopUp.Show();
}
}

============================================================

==================== WebUserControl.ascx============================

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<table>
<tr>
<td>
<asp:Button runat="server" ID="btnSim" Text="Sim" />
</td>
<td>
<asp:Button runat="server" ID="btnNao" Text="Nao" />
</td>
</tr>
</table>

==================================================================

==================== WebUserControl.ascx.cs============================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnSim.Click += new EventHandler(btnSim_Click);
this.btnNao.Click += new EventHandler(btnNao_Click);
}

protected void btnNao_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou N?o";
}

protected void btnSim_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou Sim";
}
}

=================================================================

Hi,

to handle events you need a control with an event handler to instantiated. If you only load your user control once in the click event handler, the button (textbox) in your user control does not exist on the page when postback caused by this button in user control is processed at the server.

Therefore, as you said you need to load your user control in page_load to handle events.

However, you don't need to load all controls. You just need to remeber which control was created last time and create this single control. You can store this information in the ViewState property.

Once you handled events from controls insode user control you can safely remove it from the page.

ALSO: You need to assign ID to your dynamically loaded user control. Otherwise, you will occasionally get problems with events firing from the second click.

-yuriy
http://couldbedone.blogspot.com

Difference Between Panel Extender and Accordion

What is the difference between the two other than the accordion can handle more areas to expand? Is it because it actually uses the panel control? I'm trying to think of why I would use one over the other. Thank you for ideas.Hi just_for_forums,

The difference between the CollapsiblePanel and the Accordion is the number of sections you want to have. The Accordion is like a CollapsiblePanel with multiple sections that can have ONLY ONE open at a time. That's pretty much the difference.

Thanks,
Ted

Hello Ted,

I have tried to use Collapsible panel with my page but because of the flickering of the page I will try to use accordion. Does accordion extender support <panel> and <updatepanel> inside its <content> tag>??

Thanks

Saturday, March 24, 2012

Deny a collapsible Panel Extender from collapsing if required field validators arent valid

Hi all,

I am using an collapsible Panel Extender that has a panel with textboxes used for sending a message.

When a user needs to send a message he expands the panel then fills in the boxes and presses the send button that

will send the message and collapse the panel as well.

I want to prevent the panel from collapsing if the required field validators are not valid.

I am not that great in javascript so please try and elaborate as much as possible.

Thanks.

Hi Itay,

Itay molecule:

I am not that great in javascript so please try and elaborate as much as possible.

Is is this javascript that collapses the panel?

Here is some javascript code that checks on the clientside if the page is valid. Merge this code with your javascript ;)

 <script type="text/javascript"> function checkValidity() { if (Page_ClientValidate() == false) {//handle the fact that some controls are not valid! } } </script>

If you have questions/remarks please do so!
Kind regards,
Wim


Would it be a solution to use a little updatepanel for an async postback allowing you (the server) to either:

- disable or hide the ExpandControlID ?

- (temporarily) change the target control id of the CollapsiblePanelExtender to a hidden button (style="display:none;") ?


Actually this is not an option because my collapse button is the "send" button that is supposed to check the validation

of the form.


Hi Itay,

Itay molecule:

Actually this is not an option because my collapse button is the "send" button that is supposed to check the validation

of the form.

My solution will do!
If you allow javascript in the browser offcourse.

Give me your panelcode and I'll show you what to adapt!

Kind regards,
wim


Wim Hi,

My reply wasn't ment for you i am sure your solution is the way to do it.

Here is my code thanks alot for the help.

c#

protectedvoid ImageButton1_Click(object sender,ImageClickEventArgs e)

{

sendmail sendusamail =newsendmail();

sendusamail.sendmail1(Subject.Text + "from: " + From.Text );

}

ASPX

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:ImageButtonID="ImageButton1"runat="server"ImageUrl="~/animalsbusinessid/c2a1_66.png"OnClick="ImageButton1_Click1"CausesValidation="False"/>

<asp:PanelID="Panel1"runat="server"Height="7px"Width="376px"Direction="RightToLeft"HorizontalAlign="Center">

<asp:LabelID="Label1"runat="server"Font-Bold="True"></asp:Label>

<asp:TextBoxID="From"runat="server"Columns="23"></asp:TextBox><br/>

<asp:TextBoxID="UsersEmail"runat="server"Columns="23"></asp:TextBox>

<asp:TextBoxID="Subject"runat="server"Columns="23"></asp:TextBox>

<asp:TextBoxID="Body"runat="server"Columns="30"Rows="8"TextMode="MultiLine"></asp:TextBox>

<br/>

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="UsersEmail"

Display="Dynamic"ErrorMessage="please fill in your address"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="From"

Display="Dynamic"ErrorMessage="please fill in your name"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="Body"

Display="Dynamic"ErrorMessage="write your message"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator><br/>

<asp:ImageButtonID="ImageButton2"runat="server"ImageUrl="~/animalsbusinessid/mailto_10.png"OnClick="ImageButton1_Click"/>

<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlToValidate="UsersEmail"

Display="Dynamic"ErrorMessage="this is not a valid email address"Font-Bold="False"Font-Size="13px"ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></asp:Panel>

</div>

<ajaxToolkit:CollapsiblePanelExtenderID="cpe"runat="server"

TargetControlID="Panel1"

CollapsedSize="30"

ExpandedSize="500"

Collapsed="True"

ExpandControlID="ImageButton1"

CollapseControlID="ImageButton2"

AutoCollapse="False"

AutoExpand="False"

ScrollContents="False"

TextLabelID="Label1"

CollapsedText="Show Details..."

ExpandedText="Hide Details"

ExpandDirection="Vertical">

</ajaxToolkit:CollapsiblePanelExtender>

</form>

</body>


Hi Itay,

The following code should do the trick.

More info about the $find function here:http://asp.net/AJAX/Documentation/Live/ClientReference/Sys/ApplicationClass/SysApplicationFindComponentMethod.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function handleCollapse(extenderId)
{
//Find your CollapsiblePanel Behavior on the page.
var myBehavior = $find(extenderId)

//if the page is not valid, do something
if(!Page_ClientValidate())
{
//what I do here is dispose the behavior. This way the collapse will be cancelled.
myBehavior.dispose();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="my image.jpg" OnClick="ImageButton1_Click1" CausesValidation="False" />
<asp:Panel ID="Panel1" runat="server" Height="7px" Width="376px" Direction="RightToLeft" HorizontalAlign="Center">
<asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
<asp:TextBox ID="From" runat="server" Columns="23"></asp:TextBox><br />
<asp:TextBox ID="UsersEmail" runat="server" Columns="23"></asp:TextBox>
<asp:TextBox ID="Subject" runat="server" Columns="23"></asp:TextBox>
<asp:TextBox ID="Body" runat="server" Columns="30" Rows="8" TextMode="MultiLine"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="UsersEmail"Display="Dynamic" ErrorMessage="please fill in your address" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="From"Display="Dynamic" ErrorMessage="please fill in your name" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Body"Display="Dynamic" ErrorMessage="write your message" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator><br />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="confirm_icon.gif" OnClick="ImageButton1_Click"OnClientClick="handleCollapse('cpe')"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UsersEmail"Display="Dynamic" ErrorMessage="this is not a valid email address" Font-Bold="False" Font-Size="13px" ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></asp:Panel>
</div>
<ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="server"TargetControlID="Panel1"CollapsedSize="30"ExpandedSize="500"Collapsed="True"ExpandControlID="ImageButton1"CollapseControlID="ImageButton2"AutoCollapse="False"AutoExpand="False"ScrollContents="False"TextLabelID="Label1"CollapsedText="Show Details..."ExpandedText="Hide Details"ExpandDirection="Vertical" >
</ajaxToolkit:CollapsiblePanelExtender>
</form>
</body>
</html>

If you have questions/remarks please do so!

Kind regards,
Wim


Thanks alot Wim,

Everything is almost up and running.

Just one little thing.

My collapse button doesn't collapse the panel on the first click even if the validation are valid.

Only the second time i click the button the panel collapeses back.

Any thoughts?


Hi Itay,

Hmm, that behavior is not right :)

Did you also have that behavior when you use my code example AS IS? Or is it only specific to your code?
If it is only occuring in your code, then please give me the code that replicates this behavior.

If it is also in my example, then I must say that it was not happening to me!
Can you please give me your browser version where you are noticing this behavior?
Also try your code in another browser and see if it also happens over there.

Please comment on my observations.
Kind regards,
Wim


Hi,

I tried using your code and the same thing happened. I will be more specific.

After expanding the panel i press the collapse panel in order to check that it won't collapse if not valid.

Then i fill in the required filled and press the collapse button again this time no none of the required fields error messages pop up

but the panel doesn't collapse as well then i press the collapse button again and it collapses the panel from there on

expanding or collapsing the panel works with a single click.

I did have a problem that every collapse or expanding the page would flicker (postback)

solved it with adding the

suppresspostback="true"

to theCollapsiblePanelExtender.

I am using IE7 version 7.0.5730.11

and again thanks for the help.


Wim do you have any idea to how i can resolve this problem?


Itay molecule:

Wim do you have any idea to how i can resolve this problem?

Sorry Itay that I didn't get back to you any sooner ....

I looked at the example again (the one I created):

it is not good!

Hi Wim

Every thing works great just one little thing

in order to send the message on the panel

i need the collapse button/img ti initialize a postback calling the sendmail function

is there a way that the javascript function will create the postback as well?


Hi itay,

Ok I forgot about that functionality you needed.

I didn't try it yet, but I think you could use an ImageButton for that second one. The IMG that triggers the javascript. Then just set the javascript function in the OnClientClick of it. ImageButtons have those right? Then I think it's possible to NOT let the button postback until the page is valid. Look at the button's properties. Is it the CausesValidation property, I'm not sure ...

I would go for a setup like that!

Please give it a try and if it doesn't work out I'll look into it.

Kind regards,
Wim


Wim thanks

it works just fine

still getting a page refresh on the onclick="... from the image button

but that's expected

i will try to rap it up in an update panel.

Thanks a lot

hope some day i will the ability to help you back.

Wednesday, March 21, 2012

delete ajax Extender with Javascript

hi

I have a problem with AutoCompleteExtender.

the code in HTML

<tr id="trUserName">
<td>
<asp:TextBox runat="server" id="txtUserName" />
<ajax:AutoCompleteExtender id="aceUserName" runat="server" TargetControlId="txtUserName"..... />
</td>
</tr>

when I run script below, it has errors.

var node = document.getElementById('trUserName');
node.parentNode.removeChild(node);

I have tried, if <tr /> tag without any Extender Control, it can be removed.

and I have to remove control in javascript.

Can you help me ?

Hi Benelf,

I think the best way for your situation is put them inside a div container. When you want to delete it, you can hide the div. For example,

<tr id="trUserName">
<td>

<div id="automCompleteContainer">
<asp:TextBox runat="server" id="txtUserName" />
<ajax:AutoCompleteExtender id="aceUserName" runat="server" TargetControlId="txtUserName"..... />

</div>
</td>
</tr>

To hide it , you can do it like this. document.all.automCompleteContainer.style.display ="none";

If you insist on deleting them, I suggest that you should first dispose() the AutoCompleteExtender by using $find("AutoCompleteExtender's BehavoirID").dispose().

I hope this help.

Best regards,

Jonathan

Default current date in Calendar

When using the Calendar extender, is there a way to put a default current date in the textbox?

Auto populate the text field of the textbox with <%# DateTime.Now.ToShortDateString() %> or make the assignment in code-behind.


I realized that I can assign in code behind but I don't want to do that, that's why I asked because I thought the calendar extender should allow me to do that easily. I can't do this, <%# DateTime.Now.ToShortDateString() %>, since this textbox is bind to a database.


I don't believe the calendar extender can do it automatically, but you could through JavaScript; though, you could also check the textbox and if nothing has been assigned after binding, then make the assignment.


bmains:

Auto populate the text field of the textbox with <%# DateTime.Now.ToShortDateString() %> or make the assignment in code-behind.

Okay, I thought I can try something like this:

<asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("dateCreate", "{0:d}", DateTime.Now.ToShortDateString())%>' Width="80px"></asp:TextBox><br />   

But when compile it gave me this error:

Error 1 A call to Bind was not well formatted. Please refer to documentation for the correct parameters to Bind. E:\Website\Outlook\admin\admOLissue.aspx 110

Any othe ideas?


Hello,

I'm not sure, but I don't think Bind supports the last parameter. If that is the case, you could create a public method that takes an object as such:

public function FormatDate(objDate As Object) As String
if (objDate is Nothing orelse objDate.Equals(DbNull.Value)) then
return DateTime.Now.ToShortDateString()
else
return CType(objDate, DateTime).ToShortDateString()
end if
end function

And in the textbox:

<asp:TextBox Text='<%# FormatDate(Bind("dateCreate"))%>'


Okay, I got the following error when compiled:

Error 2 The name 'Bind' does not exist in the current context E:\Website\admOLissue.aspx 110

This error comes from this line:

<asp:TextBox Text='<%# FormatDate(Bind("dateCreate"))%>'

By the way, I'm using C#.


Try using Eval instead.


If I use Eval instead of Bind, will it bind to the database if I click on the Update button?


Updates are not based on Bind or Eval statements, but on the value in textbox, not the value passed through Bind or Eval statements... If Bind doesn't work anyway, try to see if Eval will work in that context...


Okay, that seems to fix it.Thanks so much!


Hi there,

I have tried the statement with Eval and didn't work for me. When I click on edit and the field shows the correct date. But once i click on update it doesn't show anything. Is there any other possible way of doing this?

Thanks


I'd be able to help better if you posted the relevant code. Post the control you are doing this with, as well as the parent control that it is in, and how you are updating.


I think the current date ends up in the bottom of the calendar control and you can click on it to take today's date. I know this isn't great, but with a little bit of user training, it can work. I'd prefer to be able to specify today's date to be the default date as well, but since it's not available, this is the best option I could find and not have to rig it up programmatically.


bmains:

Try using Eval instead.

Not sure why, but it's not working. The value will not get updated in the database. Code in .aspx page:

<asp:TextBox ID="txtModDate" runat="server" Text='<%# defaultDate(Eval("modDate"))%>'></asp:TextBox>

Code behind:

1public string defaultDate(Object crntDate)2 {3string currentDate = Convert.ToDateTime(crntDate).ToShortDateString();4if (!String.IsNullOrEmpty(currentDate))5 {6return DateTime.Now.ToShortDateString();7 }8else9 {10return currentDate;11 }

Here is the popup error:

Cannot insert the value NULL into the column 'modDate', table "myDB.dbo.myTable'; column does not allow nulls. INSERT fails. The statement has been terminated.