Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Wednesday, March 28, 2012

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!

Saturday, March 24, 2012

Conditional Partial Page Update?

Currently, I have a page that updates data each 15 seconds. Depending on the time of day the data is being accessed, the update process could take longer than the 15 seconds when the next update should run. I've done some testing and it looks like when the page gets behind the 15 second timer, the page just keeps updating after the last one finishes until it catches up to itself.

Is there any way to make the page wait 15 seconds between each update, no matter if the update has taken 6 seconds or 30 seconds? Thanks!

Hi,

It can be achieved with window.setInterval method. You can start a asynchronous call in this method, and it waits for the specified time again and then triggers the function again.

Please try this demo:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> [System.Web.Services.WebMethod] public static string getTime() { System.Threading.Thread.Sleep(2000); return DateTime.Now.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager> </div> <input type="text" id="time" /> <script type="text/javascript"> window.setInterval(getTime, 3000); function getTime() { PageMethods.getTime(onComplete); } function onComplete(result) { $get("time").value = result; } </script> </form></body></html>

Hope this helps.

Wednesday, March 21, 2012

Composite control does update second time

So I have a composite control that allows me to generate a form with our having to write out all the table stuff. It looks some thing like:

<cc2:FieldList ID="flUsers" runat="server" LabelCellCssClass="labelCell"> <Fields> <LDAPField FieldID="NetID" Label="Net ID:" Required="true" OnLDAPFieldClick="LoadLDAPFields" /> <TextField FieldID="FirstName" Label="First Name:" Required="true" /> <TextField FieldID="LastName" Label="Last Name:" Required="true" /> <TextField FieldID="Email" Label="Email:" Required="true" /> <TextField FieldID="Phone" Label="Phone #:" Required="true" /> <TextField FieldID="Room" Label="Room #:" Required="true" /> <DropDownField FieldID="Departments" Label="Dept:" DataSourceID="sqldsDepartments" DataTextField="DepartmentName" DataValueField="ID"> </DropDownField> <DropDownField FieldID="UserTypes" Label="User Type:" DataSourceID="sqldsUserTypes" DataTextField="UserType" DataValueField="ID"> </DropDownField> </Fields> <Buttons> <Button ID="btnAddUser" runat="server" Text="Add User" OnClick="btnAddUser_Click"> </Button> <Button ID="btnClearFields" runat="server" Text="Clear" CausesValidation="false" OnClick="btnClearFields_Click"> </Button> </Buttons></cc2:FieldList>
At this point in time, we have the ability to assign events to all the buttons, and onchange events to the drop down lists. Everything works fine when there is no update panel surrounding it. We, however, would like it to work with an update panel. The control renders fine on the initial page load. It also works fine on the first event we fire such as clicking a button or changing drop down index. We run into problems when we click buttons or change indexes after that. Nothing works after. Does anyone have any ideas?

in the updatepanel do you have "ChildrenAsTriggers="false"" and do you have "UpdateMode="Conditional""? If not try UM=f first, then UM=f & CAT=f and see if that solves your problem...

p.s. setting UM=c means you'll need to use triggers to update the updatepanel fromoutside the updatepanel. anything inside that calls a postback will automatically cause the updatepanel to do an async postback

ComponentArt and Extenders

So I hope I am just being stupid, and this is a easy fix. I am using the ComponentArt callback control, because for the time being at least, they are much more powerful than the UpdatePanel. I love the extenders and want to use them. So I wish to dynamically add controls and extenders. Now the scriptmanager does not register the extenders I add in a callback. So I make a new extender on the server callback, add it to me Callback control, then let is render. The scriptmanager is at a page level and the controls are being added in a component art callback. Any suggestions? Anyone else get this to work?

ThanksHi Pinger,

I'm really not sure how ComponetArt's callback control mechanism works. I know theUpdatePanelcompletely rebuilds the client side control hierarchy when it silently handles a postback (from the high level overview on the ComponentArt website, it mentions maintaining the ASP.NET viewstate, but not the "Atlas" client side control hierarchy). We've actually had a number of bugs related to this in the past because it's a little tricky to keep your behavior consistent when it's being silently torn down and recreated. You may try posting your question on their forums as they'll know a lot more about how their callback control works with "Atlas" behaviors.

Thanks,
Ted
Thanks. I did post there too, but I am just asking here too just to see if anyone else had an idea. I will however, post it I figure it out. The UpdatePanel is very nice, there are just a few things missing from it that prevent me from switching.

Extenders are looking really good, I think some work needs to be done on adding the dynamically but I am sure that will be all worked out in the end. But regarless I would tip my hat to you guys, if they let me ware one at work that is, great job so far.