Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Wednesday, March 28, 2012

Dynamic generated Controls doesnt work, javascript error

I have an ajax enabled control which has a Dropdownlist that changes the Textbox when index gets changed. It is working fine if I use an ASPX page that contains the control in design time.

However, when I dynamically add this control to the ASPX in run time, I got an error when the Dropdownlist is triggered:

Javascript error: System.InvalidOperationException: A control with ID 'myDropDownList' could not be found for the trigger in UpdatePanel..etc..

What should I do? Please help..

There's a good chance that if you look at your page source you'll find that the dynamic control does not have a clientside Id of 'myDropDownList'. It'll probably have something more complex like ct100_myDropDownList or something.

Two possible fixes: 1) wire up your javascript on something other than the id (e.g. iterate over getElementsByTagName), or 2) render the control's ClientID inside a script tag on the page like: var ddl = '<%= myDropDownList.ClientID %>'

HOpe that helps.

Dynamic Control TextBox values not refreshed with example code

Ok, here is my situation. I have a dynamic TextBox that is added to the UpdatePanel. I need to be able to set the value of that textbox on the UpdatePanel refresh. I'm able to do that with Label control but not with the TextBox. Is that a known issue, is there a workaround? I assume i can use the standard input control possibly, but due to my project i have to use pre existing set of user controls which use TextBox. Any help is appriciated. The code is included below:

Short explanation of the example:

Example provides a link to refresh the UpdatePanel. On refresh two controls are added to the collection with specified value which is the Current time. One control is textbox and the other one is label. If you keep hitting refresh the value of the Label is changed while the value of the TextBox remains the same. Example output:test //5/11/2007 1:57:52 PM

Thanks!

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><script runat="server"> protected void Page_Load(object sender, EventArgs e) { TextBox textBox = new TextBox(); textBox.Text = DateTime.Now.ToString(); Label label = new Label(); label.Text = DateTime.Now.ToString(); test.Controls.Clear(); test.Controls.Add(textBox); test.Controls.Add(label); }</script><script type="text/javascript"> function UpdateDialogControl(val) { var ctrl = $get('<%=DialogTrigger.ClientID%>'); ctrl.value = val; __doPostBack('<%=DialogTrigger.UniqueID%>',''); }</script><body> <form id="form1" runat="server"> <a href="javascript:UpdateDialogControl(1)">test</a> <asp:HiddenField runat="server" ID="DialogTrigger" /> <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" /> <asp:UpdatePanel UpdateMode="Conditional" ID="CenterContentPanel" runat="server" RenderMode="Inline"> <Triggers> <asp:AsyncPostBackTrigger ControlID="DialogTrigger" /> </Triggers> <ContentTemplate> <asp:PlaceHolder runat="server" ID="test"></asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

In Page_Load Event, Put all the statement into the !IsPostBack block.

if (!IsPostBack)
{
//all the code
}


Okay ... the controls are not displayed at all on the refresh.

Textbox's update their value based on the posted value from the previous request. So you're adding it, then its getting updated, overwriting your set value. Disabling ViewState will not affect this, since the value comes from the posted values collection, not viewstate.

Normally TextBox's are updated by the time you get to OnLoad, but since this TextBox didn't exist at that time, it isn't updated until AFTER OnLoad.

So -- heres what you do...

Add the TextBox in OnInit instead. Then in OnLoad, you can set the value to whatever you want, knowing full well that the posted value has already been loaded.

I recommend you follow the link to my blog and read about dynamic controls :)


Hi, thanks for the answer. However ... I do understand how ViewState works and that you need to add controls dynamically during or before OnInit event in order for them to keep track of viewstate. Your solution will indeed work for that specific example. I need an ability to remove all the controls and add completely new ones on refresh with values i specified.

Actually this specific problem is not related to ViewState at all. Its the POST state of the textbox that is in question here. Even if you turned off viewstate to the entire page this same solution would apply. Dynamically added controls can keep track of their own viewstate no matter when you add them to the tree (as long as its before SaveViewState, which is between PreRender and Render).

If what you want is to destroy all the existing controls and start with fresh ones, its ok to clear to the control tree and start a new one -- but you have to give the existing controls a chance to load their prior state first, so that they "consume" that data. So you would do this in Load, or in response to an event (like a click event, which would be raised after Load).


So you are saying i have to add old controls before load event then in OnLoad even clear the controls collection and add new elements with a values i specified? (in the example above i'm adding controls in the Onload event).

BTW, I did not have the same problem without UpdatePanel it seems like it is adding extra remember state feature ...

Thanks for replies btw.


Nm, UpdatePanel does behave like any other control. It is not related to any extra remember state feature ... I guess i never encountered problem when i needed to completely refresh controls and yes you are right I did it on the SelectedIndex changed event before which worked fine. Now i need to do it on UpdatePanel refresh and this is where i'm having issues.

Thanks for the post again. I indeed needed to rebind the form on the event. So in case of UpdatePanel it was the ValueChanged event for the hidden input control. Just like you told the viewstate is restored when form is bound on OnLoad event and then when i bind it second time i can put new values for the controls.

Thanks!

Dynamic Ajax Filter C#

I am trying to create a custom ajax filter using code, so far i can filter the textbox with either LowerCaseLetters, or UpperCase etc. but not all 3 and some custom chars. My code at the moment is ;

AjaxControlToolkit.FilteredTextBoxExtender Filter = new AjaxControlToolkit.FilteredTextBoxExtender();
Filter.ID = "Filter" + i.ToString();
Filter.TargetControlID = "NameBox" + i.ToString();
Filter.FilterType = AjaxControlToolkit.FilterTypes.LowercaseLetters;
Filter.FilterType = AjaxControlToolkit.FilterTypes.UppercaseLetters;
Filter.FilterType = AjaxControlToolkit.FilterTypes.Custom;
Filter.ValidChars = " ";
Page.Controls.Add(Filter);

How do you use more than one filter in dynamic filters? thanks John

Hi,

You can use or operator to apply more than one FilterType simultaneously. For example:


Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.LowercaseLetters;
Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.UppercaseLetters;
Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.Custom;


Like this:

Filter.FilterType = AjaxControlToolkit.FilterTypes.Numbers | AjaxControlToolkit.FilterTypes.Custom;
Filter.ValidChars = ".";

Monday, March 26, 2012

Dyanimc TextBoxWatermark in GridView Pager Template

I have a textbox in my gridview pager template to allow the user to enter a page number to jump to. I would like the watermark to read Page X of Y. I tried to set the watermark text on the GridView_DataBound event, but that doesn't work.

My guess is this occurs because most (if not all) AJAX controls render client scripts durning the preload event and the databound event executes long after the preload. Is this correct? Is this by design? Will AJAX controls always render in the preload event?

Is there a workaround I could use to generate thePage X of Y for the watermark via javascript or something?

Thank you for your assistance

This should work - have a look at the DataBinding.aspx page in the ToolkitTests directory for an example. If you're still stuck, please post a complete, self-contained sample demonstrating the issue. Thanks!

DropShadowExtender and SetFocus

Hi there,

I'm trying to set the focus to a textbox while using the DropShadowExtender, but it does not seem to work.

The code is something like this:

<asp:Panel id="panelContainer" runat="server">

<asp:Textbox id="txtName" runat="server" />

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="dseLogin"runat="server"><atlasToolkit:DropShadowPropertiesTargetControlID="panelContainer"Width="5"Rounded="true"Opacity=".75"TrackPosition="true"ID="dsBehavior"/></atlasToolkit:DropShadowExtender>

And in the code behind:

protectedvoid Page_Load(object sender,EventArgs e)

{

this.SetFocus(this.txtName);

}

What am I doing wrong? Is this a bug? Is there a workaround?

Thanks,

Rudy

Try searching this forum group (groupid:34) for SetFocus, I seem to recall seeing a post about this emitting code that couldn't be read correctly by Atlas. Maybe? I'm taking a stab but try to find the existing posts.
I did search for similar problems with SetFocus, but the posts I found were related to the TextBoxWatermarkExtender, not the DropShadowExtender.

This problem happens (I think) because the ASP.NET call to WebForm_AutoFocus (inserted by Page.SetFocus) happens before Atlas load. When Atlas loads and DropShadow initializes, it needs to mess around with the DOM and I think the manipulations it does end up losing the focus. My recommendation is to set the focus with the following instead as Application.load fires only AFTER Atlas and related code is finished initializing:

<script type="text/javascript">
Sys.Application.load.add(function() { $("txtName").focus(); });
</script>

The complete sample follows:

<%@. Page Language="C#" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="ScriptManager1" runat="Server"> </atlas:ScriptManager> <asp:Panel ID="panelContainer" runat="server"> <asp:TextBox ID="txtName" runat="server" /> </asp:Panel> <atlasToolkit:DropShadowExtender ID="dseLogin" runat="server"> <atlasToolkit:DropShadowProperties TargetControlID="panelContainer" Width="5" Rounded="true" Opacity=".75" TrackPosition="true" ID="dsBehavior" /> </atlasToolkit:DropShadowExtender> </div> </form> <script type="text/javascript"> Sys.Application.load.add(function() { $("txtName").focus(); }); </script></body></html>

Wednesday, March 21, 2012

dropdownlist

Hello All,

I have three dropdownlists and a textbox on my web page. The dropdownlists display the Day/Month/Year respectively.

I set the dropdownlists to display today's date when the page loads and the textbox displays the values from the dropdownlists as a single string value.

How can i dynamically change the dates in the dropdownlist for example ( instead of december 2007 to december 2008)and have the new changes displayed in the textbox?

The easiest way is to put your textbox inside an update panel like this:

 

<asp:UpdatePanelID="updPanel"runat="server"UpdateMode="Conditional">

<ContentTemplate>

<asp:TextBoxID="txtDate"runat="server"/>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="DropDownList"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

Now in the SelectedIndexChanged event handler, just set the textbox to the new text. That's it!


Thanks oswaldorb,

It works but not as i want it to.

I would like the default date to be the current date for example 13/12/2007 when the page loads initially.

But when i try to do change the default date, i get an error

Please help!

DropDownExtender: Edit TextBox attached to DropDownExtender

Is there a way to edit the textbox that is attached to the dropdownextender.

1<asp:TextBox ID="txtLocation" runat="server" OnTextChanged="txt_TextChanged" />
2 <cc1:DropDownExtender ID="DropDownExtender1" runat="server" DropDownControlID="Panel1" TargetControlID="txtLocation">
3 </cc1:DropDownExtender>

I have tried adding a textbox to Panel1 but it disappears as soon as i click on it.

Marty

My guess would be that once the TextBox in the Panel receives focus, the Panel loses focus, and that causes the Extender's script to think that it should close the Panel.

It sounds like you need a Panel that doesn't auto-close and you have to manually close. That way you can do data entry on the Panel.


And how is that done?
Popup window, modal dialog, roll your own iframe or floating div...

Hi ,

I am facing same problem.Can you please tell me how can I solve it?

Many thanks,

Ramesh.


Any solution about this issue ?

DropDownExtender question

Can I use the DropDownExtender to create a google suggest textbox? If not, is there another control i can use to do this, or do I have to build my own?

Thanks

sorry...what is google suggest textbox

http://www.google.com/webhp?complete=1&hl=en

The AutoCompleteExtender does what I want but I'm not sure how to send the textbox value to the webservice to sort the dataset. Here's my code...

 <asp:TextBox ID="txtTest" runat=server></asp:TextBox> <asp:AutoCompleteExtender ID=ace1 runat=server TargetControlID="txtTest" ServicePath="WebService.asmx" ServiceMethod="getZoneSuggestions" MinimumPrefixLength="1" />
[ScriptMethod] [WebMethod(EnableSession =true)]public string[] getZoneSuggestions(string test) {string[] result; result =new string[4]; result[0] ="atest1"; result[1] ="atest2"; result[2] ="btest2"; result[3] ="btest2";return result; }
When I try to pass the string into getZoneSuggestions nothing happens, but when I remove "string test" it will show all of my results.
 

I figured it out.

[ScriptMethod] [WebMethod(EnableSession =true)]public string[] getZoneSuggestions(String prefixText,int count) {string[] result; result =new string[4]; result[0] ="atest1"; result[1] ="atest2"; result[2] ="btest2"; result[3] ="btest2";return result; }

DropDownExtender problem

Hi all...

I have problem with DropDownExtender.

There is on the page have placed DropDownExtender and disabled TextBox Control with some text.

When I make right click on the text in disabled textbox, I get JavaScript error like "Object doesn't support this property or method". (Problem with getClientRects function in Script sources file)

Simple content page:

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestApp.Default" Title="Untitled Page" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server"><table cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> <asp:Label ID="lblLinkName" runat="server" Font-Size="12px" Text="Show Links" Style="display: block; padding: 2px; padding-right: 20px; color: White;font-size:12px;font-weight:700;font-family: Verdana,Arial, MS Sans Serif, Tahoma;" /> <asp:Panel ID="DropPanel" runat="server" Style="display: none; visibility: hidden; background: White;"> <table cellpadding="2" cellspacing="0" border="0" style="width:150px; border: solid 1px Gray;"> <tr> <td><asp:LinkButton ID="lnkFirst" runat="server" Text="First Link" /></td> </tr> <tr> <td><asp:LinkButton ID="lnkSecond" runat="server" Text="Second Link" /></td> </tr> <tr> <td><asp:LinkButton ID="LinkThird" runat="server" Text="Third Link" /></td> </tr> </table> </asp:Panel> <ajaxToolkit:DropDownExtender runat="server" ID="DDE" TargetControlID="lblLinkName" DropDownControlID="DropPanel" HighlightBackColor="#256294" HighlightBorderColor="white" /> </td> </tr> <tr> <td> </td> </tr> <tr> <td><asp:TextBox ID="txtField" runat="server" Width="200" /></td> </tr></table></asp:Content>
 CodeBehind:
 
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;namespace TestApp{public partialclass Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) { txtField.Text ="Hello World!"; txtField.Enabled =false; } } }}

Try to reproduse this bug or leave your email and I send example.

Please help.Sad

DropDownExtender breaks the XP theme of TextBox

Guys I have problem with DropDownExtender which extends TextBox control.

Step 1. Before mouse is over the TextBox:

Step 2. Mouse is over the TextBox:

Step 3: Mouse is out of TextBox:

As you can see TextBox has become old-style designed. Any advice is appreciated

Hi,

I've tested it,didn't run into the same probem.

If you haven't resolved the problem yet,please feel free to provide us with a repro of it.

Thanks


We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.