Wednesday, March 28, 2012

control inside an update panel not updated

i have a dropdown list inside an update panel of ajax, i have a button that says "Add" on the click event of the button i will load a pop-up screen. the popup screen works as entry area of the drop down list i have mentioned. upon saving and unloading the pop-up screen, it should update the dropdown list contents. any help please, this is my first time to handle ajax..

Hi,

You question is about cross window scripting.

First, find the dropdownlist in the parent control.

var ddl = window.opener.document.getElementById("id of the ddl");

then add new item into it:

ddl.options.add("new value");

Hope this helps.

Control inside a DropDownList

Hi,

Is it possible to insert controls such as buttons, etc... inside a dropdownlist ?

hello.

not inside the traditional dropdownlist. i guess that you could fake it though by using javascript...


thank you

Control ID Changed and GetElemntByID Return NUll

I have this code

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:TextBox ID="TxURL" runat="server"></asp:TextBox>
<asp:Button ID="Test" runat="server" Text="Button" OnClick="Test_Onclick" />
</ContentTemplate>
</asp:UpdatePanel>

I try to run this script

var TextControl= document.getElementByID("TxURL")

or

var TextControl = $get("TxURL")

but return value is NULL.

so How, to get Item in Client with the orignal Name. not the generated Name

Thanks.

U may be using Master Pages or UserControl thats why the client id of the control are not the same which u give to the control on the design time

try to run this script

var TextControl= document.getElementByID("<%= TxURL.ClientID %>")

or

var TextControl = $get("<%= TxURL.ClientID %>")

Control focus on autopostback in UpdatePanel

I have an Update Panel with a bunch of textboxes, and have code for the _onTextChanged events of some of them, so I have enabled AutoPostBack=true.
This is a data entry screen, so the TabIndex is critical. In Mozilla, when the textbox posts back, the TabIndex moves to the next box as expected. In IE, the reload of the page seems to reset the TabIndex to the first textbox.

Any ideas on how I can make my code behave in IE like it does in Mozilla?

ThanksActually, I asked same question yesterday. Unfortunately, no answers yet.
You could use Control.Focus(), to manually set the focus to the next control (either in the server code or with javascript).
That's the strange thing about it... I already had that, and I watch it work in stepping through the _onTextChanged of the control, but then the focus just gets changed/set to nothing after my code set it properly...

Control Focus Inconsistent in Updatepanel on Update

Hi,

Any help would be appreciated in regards to the following problem:

I'm creating calculator-type applications and having problems with focus being lost from textbox controls that are inside of UpdatePanels when my UpdatePanels refresh. Because of the nature of the calculators, all of my textbox fields need to be inside of the update panel. As each textbox is filled out (which can be done in any order) other textbox values will change and adjust. This is all done using the July CTP of Atlas, and the TextChanged events of the TextBox controls.

My problem is that once a user changes the value of a textbox, the UpdatePanel refreshes (to adjust the other textboxes) causing the cursor to unfocus from the newly selected TextBox.

Thus, if the user tabs into a textbox in my UpdatePanel and adjusts the value, then presses tab again, their cursor will momentarily highlight the next textbox and then disappear entirely when the UpdatePanel is updated.

Thanks!

-Snickers

Use Javascript to do calculations and avoid code behind . your problem will be solved.

if there is some connectivity with database or some major code then use code behind

hope it helps

http://www.devguru.com/technologies/javascript/home.asp

Control Focus in ASP.Net 2.0 using AJAX, Master Pages, user controls...

Having a heck of a time with this... Any assistance would be appreciated. All I need to do is set focus to a textbox control that is inside an AJAX tab container (has 2 tabs) that is inside a user control that is inside the content page of a master page. I've tried everything from setting the default focus in the master page to calling .focus() on the textbox to custom javascript and cant get anything to work. Is there something I'm missing here? I'd like to somehow set the focus at the content page level if possible.

Thanks,Troy

I usually set the focus by custom javascript and not use any asp.net built-in feature for this.

I use this javascript function:

function setFocus( id )
{
var o = document.getElementById( id );
if(o != null && !o.disabled ) { o.focus(); }
}

And I have this just before closing the body tag, but can be other place:

<script type="text/javascript">

setFocus( "yourcontrolid" );

</script>

The real question is how to get the corrent id for your control?

You can do this for example:

setFocus( '<%= yourcontrol.ClientID %>' );

You can also hard-code the control id, you can find-out your correct control id by examining the source view of your html page (if the control is rendered during an async postback the page source view not reflect the changes, you need some debugging tool to see your real html source, firebug etc.)


Hadn't thought of inline script. I tried the above, but am still getting the following error: guessing it's an AJAX tab container thing:

"htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."

Here's what I did: Exposed the textbox's clientID in a string property from the child control; Added setFocus(id) sccript to the master page's head tag;At the end of the content page's Page_Load event (server), added aRegisterStartupScript for setFocus passing in the clientID property.

When debugging the above error, my textbox (Input element) makes it into the setFocus() function, is enabled, etc, etc, ... ??

I'll continue to search on the above error. Thanks for the input stmarti...


Found a workaround. (seehttp://forums.asp.net/t/1184754.aspx?PageIndex=3) I ran across this before but am using it as a last resort... "Slowing down" the app doesnt seem like the correct solution but will have to do. I worked a delay routine into the setFocus() solution stmarti suggested. Did the same as above with the following changes in the master page (and calling delay using RegisterStartupScript in content's page_load instead of setFocus):

function delay(id){setTimeout("setFocus('"+id+"')",500);

}

function setFocus( id ) {

var o = document.getElementById( id );if(o !=null && !o.disabled ) { o.focus(); }

}

Anyone with a more elegant solution, please post. Thanks!


What about this (no delay required I think)?

<script type="text/javascript"
Sys.Application.add_load( function( )
{

var o = document.getElementById( yourid );

if(o !=null && !o.disabled ) { o.focus(); }


} );


</script>

You can try other events also (ASP.NET AJAX > Overview > ASP.NET AJAX Client Life-Cycle Events )


Looks like the above is what I'm looking for - wont get a chance to investigate for a bit. Thanks!

Control Extenders inside View Templates?!?

In the previous versions of the toolkit I could place a control extender inside a view template and everything worked just fine but with today's release (10-20-2006) this appears to have broken.

I have verified this to be true with the TextBox Watermark Extender, the Drop Shadow Extender, and the Rounded Corners Extender.

As an example:

<asp:ScriptManager ID="scriptManager" runat="server" />
<asp:LoginView ID="loginView" runat="server">
<AnonymousTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="tbw" runat="server" TargetControlID="TextBox1" WatermarkText="WaterMark" />
</AnonymousTemplate>
</asp:LoginView>

This code worked fine in the last version but in this version I do not see the watermark.

Is anyone else experiencing this? If there another way to do this?

Thanks

Sean

The fix is to add the following to your page:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
loginView.DataBind();
}

The reason is outlined here:http://forums.asp.net/thread/1441672.aspx.