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

Monday, March 26, 2012

Updatepanel + javascript

privatevoid TimerTickMethod(){

HtmlGenericControl inc =newHtmlGenericControl("script");

inc.Attributes.Add("type","text/javascript");

inc.InnerHtml ="alert('Merhaba Dünya');";

Page.Header.Controls.Add(inc);

}

There is no explanation as to what you're trying for? Are you saying that this doesn't work? Try:

private void TimerTickMethod(){ ClientScript.RegisterStartupScript(this.GetType(),"alert('Merhaba Dünya');",true);}

Excuseme, I couldn't write explanation couse i have no time. Now, i can.. Before I couldn't add a javascript code which will work every Tick Event. I just found and sent to forum. It's working now.

UpdatePanel + StartupScript + Sys.Timer

I'm using an UpdatePanel with a user control somewhere in there. The usercontrol registers a client startup script (ClientScript.RegisterStartupScript) in which a Sys.Timer object is created.

When the updatepanel refreshes via Atlas, the startup script gets executed again (which I believe is expected behavior), causing a new Timer to be created.

The old timer is still around though, causing the tick event handler code to be executed twice as often as required.

What would be the best way to get around this? My current solution has been to update the startup script code to skip timer creation if a timer already exists. Another solution I could think of would be to call dispose() on the old timer at that time.

Is there a way to register client script to execute when an asynchronous postback occurs? In case the resulting updatepanel contents no longer contains the usercontrol with timer, it would be wise to dispose the timer at such a time.

Greetings,

Wouter

hello.

i think that you have several options...for instance, you could use the ispostback property of the page (it'll be false on the 1st rendering; since you only want to add the timer one time, this could solve your problem)...


Luis Abreu:

i think that you have several options...for instance, you could use the ispostback property of the page (it'll be false on the 1st rendering; since you only want to add the timer one time, this could solve your problem)...

Not really sure about IsPostBack. The scenario where I encountered this problem involved webparts in an updatepanel, where the timer is created by one of the webparts. When starting with a blank page and adding the webpart with timer, IsPostBack will be true.

Also, when this webpart is removed from the page, my feeling is that the timer should be stopped.


hello again.

hum...then, you can probably do something like this:

1. add the timer through xml-script
2. on the clientregistermethod, start the time
3. when the web part is removed, inject client script to stop it

Saturday, March 24, 2012

UpdatePanel and client-side script error in IE, but not in Firefox

<atlas:UpdatePanel runat="server" ID="up" Mode="Always">
<ContentTemplate>
All sorts of controls here
</ContentTemplate>
</atlas:UpdatePanel
I have two DropDownLists. When the user selects an item in the first DropDownList, there is a postback and the 2nd DropDownList gets populated.

All works fine in Firefox 1.5.0.1.

In IE 6, I get this client-side error:
"Assertion Failed: elements in children collection should always have nodeType = 1
Break into debugger?"

And if I break into debugger, the only line is:
"debugger;"

Thanks.Dear,

I have this problem now :)

[],

Ramon Dur?es
It would be nice to post a complete code or at least something distilled down to generate the same error. Both posts claim some issue, but without the code it's difficult for others to investigate this problem.
OK, this was not easy to reproduce. It's a crazy bug :)

<%@. 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">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList2.Items.Add(new ListItem("xyz"));
}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<atlas:ScriptManager ID="sm" runat="server" EnablePartialRendering="True" />
</head>
<body>
<form id="form1" runat="server">
<div>
<atlas:UpdatePanel runat="server" ID="up" Mode="Always">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>abc</asp:ListItem>
<asp:ListItem>def</asp:ListItem>
</asp:DropDownList><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="DropDownList1"></asp:RequiredFieldValidator>
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<!-- remove this to make UpdatePanel work in IE -->
</ContentTemplate>
</atlas:UpdatePanel>
</div>
</form>
</body>
</html
Just remove the HTML comment, and it works!
Hi,

please checkthis thread.
Hi

I have had this problem with the March release. removing thecomments did resolve it. However i dont understand why this is?
I guess its not a big problem to simply not comment in the html but still seems like a strange restriction.

Garbin. You mention in the other thread that the release fileswill not do this and recommend to reference them? I dont follow, i addthe script folder to my project and create a reference to thedll. Then in the config file....
<add tagPrefix="atlas" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas"/>
<add tagPrefix="atlas" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas"/
How do i specifically refrence the release js files?

thanks
o
I got the same problem. I have the latest dll and took all the comments off the page.

I have this textbox that when it posts back it finds the client. If I use it with Firefox it works (after I took off the comments), but if I use IE, it does the search but it freezes up and never shows the information.

Thanks.
Hi,

you could use the ASP.NET notation

<%-- This is a comment --%>

to make comments inside an UpdatePanel.
Now I don't get the error message, but the page freezes up.

I'm using master page, and when I use regular page it works fine and all the fields are completed, with the master page, it finishes the search and that's it, no error message at all.

Thanks.
Hi,

the problem may be related to the id of a control being modified by its container (the MasterPage), but I'm just guessing. Could you post some code?
Thanks for your answer Garbin.

I don't know if this is relative or not, but the master page was using MagicAjax, so I just deleted the MagicAjax Panel from it and it worked.

My guess is the MagicAjax javascript was modifying something. Now it works.
I have the problem too.
and I a another problem.
when I use UpdatePanel on the webPart Zone Control.one webpart zone left a Updatepanel,but when I drop the webpart from a webpart zone area to another.
there will show the message:
"Assertion Failed: Duplicate use of id "WebPart_gwpBookConsumer1" for object of type "Sys.UI.Controls.WebParts.WebPart".Break into debugger?"

The problem exists in Firefox too.

thanks.
same problem here

This is a known issue, and we are currently investigating. See this thread:http://forums.asp.net/thread/1232325.aspx

-Mike


Is fixed in the Atlas April CTP:http://weblogs.asp.net/atlas/archive/2006/04/10/442437.aspx

-Mike

Wednesday, March 21, 2012

UpdatePanel and Legacy conformance

I am wondering if support for atlas in<xhtmlConformancemode="Legacy"/>is going to be added? The script code will only substitute out the $ for _

function uniqueIDToClientID(uniqueID){return uniqueID.replace(/\$/g,'_');

Previous versions of ASP.NET used : instead of $

Hi, that's a great catch - I opened a bug to track this issue. I'm not entirely sure if we will support that, since a lot of the things that UpdatePanel does requires XHTML compliance anyway, though we are relaxing some of those restrictions to better support existing applications.

Thanks,

Eilon

UpdatePanel and OnBlur

Background: I have a script which attaches event listeners to OnFocus and OnBlur of my form controls after the page has loaded. The script updates a DIV with information about the element when focused and resets the DIV when blurred. My controls are wrapped inside an UpdatePanel.

The Problem: After the AsyncPostBack has occured my event listeners no longer work. The page is meant to redirect if all the fields are valid, so I am using validators - if the page is invalid it will not redirect and it is at this point that the event listeners stop working.

The Questions: Why are my event listeners not working after the AsyncPostBack? Is there a way to permanently register an event listener?

Also, now that I think about it... Are my validators overwriting the events? The validators only do custom server-side validation, no client-side.

how did you add the javascript to your controls?
like so:
textbox1.attributes.add("onblur","checkme(self);"); ?

could you perhaps post some more code?


I'm using javascript to gather all my form fields and add the listeners through the javascript. This works just fine, my code executes correctly. The problem is right after an AsyncPostBack.

My javascript load:

var fh = new formHelper();
fh.form = 'fm'; // Starting element
fh.divDisplay = 'divNote'; // DIV to display info
fh.helpForm(); // Load the event handlers

This is what adds the event handlers (this uses Prototype)

// Add event handler
if (elementsFound[x].title.length > 0) {
Event.observe(elementsFound[x], 'focus', this.getElementNote.bindAsEventListener(this));
Event.observe(elementsFound[x], 'blur', this.getElementNote.bindAsEventListener(this));
}

Everything works until the AsyncPostBack. My update panel is set to conditional and trigger is set to my btnSubmit.Click


I see..I had the exact same problem, but couldnt get it to work..
check here, perhaps it does help you:http://forums.asp.net/thread/1545416.aspx

if not I suggest you attach the javascript code via the attributes.add method..(if possble)

HTH

I managed to find a way to accomplish it.

In my btnSubmit_Click before I do the page.isValid check I re-register the script through the ScriptManager:

ScriptManager.RegisterStartupScript(btnSubmit, Page.GetType(),"fh", _ "var fh = new formHelper();fh.form ='fm';fh.divDisplay = 'divNote';fh.helpForm();", _True)
Thanks for helping me get started in the right direction