Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Wednesday, March 28, 2012

multiple update panels each with a timer

I have a very simple page. It has 1 script manager and 2 update panels. Each update panel has a label and a timer. the timers are set 1 second and each simply updates the label with the current time. The first timer works and displays the time. The second never fires. Any one have any ideas? Here is the page...

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeBehind="Default.aspx.cs"Inherits="WebApplication1._Default" %>

<%

@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>

</div> <asp:UpdatePanelID="UpdatePanelFirst"runat="server"><ContentTemplate><asp:TimerID="TimerFirst"runat="server"Interval="1000"OnTick="TimerFirst_Tick"></asp:Timer><asp:LabelID="LabelFirst"runat="server"></asp:Label></ContentTemplate></asp:UpdatePanel><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:TimerID="Timer1"runat="server"Interval="1000"OnTick="Timer1_Tick"></asp:Timer><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></ContentTemplate></asp:UpdatePanel></form>

</

body>

</

html>

and the code behind.

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

WebApplication1

{

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protected

void Timer1_Tick(object sender,EventArgs e)

{

Label1.Text =

DateTime.Now.ToShortTimeString();

}

protectedvoid TimerFirst_Tick(object sender,EventArgs e)

{

LabelFirst.Text =

DateTime.Now.ToLongTimeString();

}

}

}

I am not sure about your requirement. If you are trying to update both the labels at the same time one timer will do.

But if you want both the Timer ticks to work modify your code as follows:

protected

void Timer1_Tick(object sender,EventArgs e)

{

Timer1.Enabled =

false;

Timer2.Enabled =

true;

Label1.Text = System.

DateTime.Now.ToLongTimeString();

}

protectedvoid Timer2_Tick(object sender,EventArgs e)

{

Timer2.Enabled =

false;

Timer1.Enabled =

true ;

Label2.Text = System.

DateTime.Now.ToLongTimeString();

}

Monday, March 26, 2012

MutuallyExclusiveCheckBoxExtender doesnt work if elements are added dynamically

I create my table on the fly and added checkboxes as well as MECBextenders.

The client script is not working on the page. It works as expected if the MECBs are added during design time.

Here is some code to demonstrate population:

1string extenderKey ="AllTheSameKey";23foreach (MvpPoint pointin _selected.FolderPoints)4 {5678switch (point.PointType)9 {10case tPointType.DO:11case tPointType.CP:12 {13continue;14 }15default:16 {17 trow =new TableRow();1819 CheckBox chkSelected =new CheckBox();20string sPointId = point.Handle.ToString();21 chkSelected.ID ="chk" + sPointId;22 chkSelected.Visible =true;23if (point.PointType == tPointType.AI)24 chkSelected.Enabled =true;25else26 chkSelected.Enabled =true;2728 AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender chkExtender =new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender();29 chkExtender.ID ="chkExt" + sPointId;30 chkExtender.TargetControlID = chkSelected.ID;31 chkExtender.Key = extenderKey;32

The problem ONLY exists if the MutuallyExclusiveCheckBoxExtender is cointeined inside a TabPanel. The IDs get changed by the cointeiner control and the jscript fails to find them.

My (Un)Modal Popup

I have added a modal popup to my user control. I show the modal popup by registering a startup script in the code-behind of an update panel trigger. The modal popup appears, but it isn't modal. I can click and edit the form fields behind the modal popup. Has anyone seen this happen? Any thoughts on how to fix it?Post code and I might be able to help you

Have you set the BackgroundCSSClass properly? I saw the same behavior and was able to fix it by setting the BackgroundCSS... here's an example of the CSS I used

.modalBackground

{background-color:Gray;filter:alpha(opacity=70);

}


I used below css but still my main page controls can be accessed?

.modalBackground

{background-color:Gray;filter:alpha(opacity=70);

}

This is happening in (Un)Modal fashion, any have solution for this.

My first Ajax use

Hello Friends

I am having a DropDownList "lstTitle" that read its values from SqlDataSourse "DSTitles" and a Label "lblNewTitle" i add a java script to the lblNewTitle like that:

lblNewTitle.Text ="<a href='javascript:window.open(\"AddNewTitle.aspx\",\"window\",\"HEIGHT=272,WIDTH=440,top=250,left=250,toolbar=no,scrollbars=yes,resizable=yes\");%20void(0);'>New Title</a>";

so when press on that label a new window appear that enable the user to enter a new title in to my sql 2000 database.

The problem is how to show this new entered title in the lstTitle without a PostPack action.

Note: i add to my page a ScriptManager and and UpdatePanel and put "DSTitle,lstTitle and lblNewTitle" inside the UpdatePanel and use a Timer with an interval of 1 second but nothing change.

So, where is the problem.

Please help me.

Hi.

Label1.Attributes.Add("onClick", "javascript:window.open('Default.aspx',height=272,width=500)");

This will help you.. sure...Remove your first logic and write this intoyour page load event and test it.

Thanks


I just have a script error "Error: 'Sys' is undefined i think the problem is in the following includes:

<%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>

Hello,

not answering question, but just throwing an idea out: how about using the modalpopupextender instead of a popup window?


Thanks i found the solution.

I create a new website AJAXEnabledWebsite and but a script manager, UpdatePanel "and but the control inseide" and a Timer with an interval of 9 sec and a Tick event.

Inside Timer event handler i put:

lstTitle.DataBind();

lstTitle.SelectedValue = selected;

Wednesday, March 21, 2012

Need help with RegisterClientScriptResource

I am having a huge problem withRegisterClientScriptResource - I can't seem to keep it from re-registering the same script over and over. I have a control called a Popup (a floating div) which has to inject some javascript when added to the page. The problem is, there can be several Popups on a given page, and if so, the javascript is being injected several times, once for each Popup on the page. I've done my best to word things properly, but it's just not stopping the multiple instances. Here is a sample command that is causing the problem:

ScriptManager.RegisterClientScriptResource(Page,typeof(Popup),"Framework.Bus.Resources.javascript.popup.js");

And I have also tried:

ScriptManager.RegisterClientScriptResource(this,typeof(Popup),"Framework.Bus.Resources.javascript.popup.js");

Notice that I amNOT using GetType(), which is what every article in existance seems to indicate would be causing the problem. This commandIS part of a "base class" which is always inherited from.

What am I doing wrong? Barring that, is there a way to test if the script in question is already injected, so that I can just avoid re-injecting the same script?

Just giving this a nudge because I'm in a tough situation and can't seem to figure it out. I really need some assistance, if anyone has info about this. - Thanks
Daily bump - any ideas?

I have the same problem. Now I have my page inherits IScriptControl and use GetScriptReference to register scripts.

btw, for it to work you will have to call ScriptManager.registerScriptControl in render override.


Rushui

Need information on Preview scripting

It seems that a lot of client side script was moved to Preview part. Is there any documentation what is in preview and some examples?

Second question:

How do I get $get for server side controls? Let say TextBox with server side id="textName" may have very long name on a client. Is there a way to get hold of that control using it server ID?

Thanks

Answer for first question I figured out.

$get('<%=textName.ClientID%>)

For second I found

http://www.asp.net/downloads/futures/

But I still don't see any client script reference, like where is Sys.Preview.UI.TextBox information.

Thanks


Hi,

I think you've found the answer to your second question. That's : $get('<%=textName.ClientID%>)

The generated client ID can be got in the way like your code.