Showing posts with label bit. Show all posts
Showing posts with label bit. Show all posts

Monday, March 26, 2012

Will calling .click() fire an updatepanel Trigger?

This might seem a bit silly but...

Basically, I have a javascript function which calls the .click() method of a button, this button resides outside of any UpdatePanels

This button is also set as a trigger for one of my UpdatePanel controls.

My problem is, the button click runs fine, the server side click event fires ok and rebinds some data for a GridView which is inside the UpdatePanel, but the UpdatePanel does not update its contents.

Do you have to physically click the button with your mouse to cause the Trigger? Or should the programmatic javascript call to click() work?

No will not cause it trigger, you need a postback for that, not a javascript call


You cantrigger an UpdatePanel refresh from the client side, using __doPostBack().

Hi

The programmatic javascript call to click() should work, you must do something wrong.

Look this sample:

<%@. Page Language="C#" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="http://links.10026.com/?link=StyleSheet.css" mce_href="StyleSheet.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
var styleToSelect;
function onOk() {
$get('Paragraph1').className = styleToSelect;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<p id="Paragraph1">
GetContentFillerTextGetContentFillerTextGetContentFillerTextGetContentFillerText</p>
<br />
<ajaxToolkit:Accordion ID="Accordion1" runat="server" ContentCssClass="grey" FadeTransitions="false"
FramesPerSecond="25" TransitionDuration="250" HeaderCssClass="dimgreen" EnableViewState="true">
<Panes>
<ajaxToolkit:AccordionPane runat="server" ID="PaneOne">
<Header>
AccordionPane0
</Header>
<Content>
<a href="http://links.10026.com/?link=javascript:return false" onclick="javascript: LinkButton1.click()">Click here to change
the paragraph style</a>

</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
<div style="visibility: hidden">
<asp:LinkButton ID="LinkButton1" runat="server" Text="Click here to change the paragraph style" /></div>
<asp:Panel ID="Panel1" runat="server" Style="display: none" CssClass="modalPopup">
<asp:Panel ID="Panel3" runat="server" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black">
<div>
<p>
Choose the paragraph style you would like:</p>
</div>
</asp:Panel>
<div>
<p>
<input type="radio" name="Radio" id="RadioA" checked="checked" onclick="styleToSelect = 'sampleStyleA';" />
<label for="RadioA" class="sampleStyleA" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioB" onclick="styleToSelect = 'sampleStyleB';" />
<label for="RadioB" class="sampleStyleB" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioC" onclick="styleToSelect = 'sampleStyleC';" />
<label for="RadioC" class="sampleStyleC" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioD" onclick="styleToSelect = 'sampleStyleD';" />
<label for="RadioD" class="sampleStyleD" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p style="text-align: center;">
<asp:Button ID="OkButton" runat="server" Text="OK" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</p>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server"TargetControlID="LinkButton1"
PopupControlID="Panel1" BackgroundCssClass="modalBackground" OkControlID="OkButton"
OnOkScript="onOk()" CancelControlID="CancelButton" DropShadow="true" PopupDragHandleControlID="Panel3" />
</div>
</form>
</body>
</html>

Thanks

Saturday, March 24, 2012

Works in IE but not in Firefox ...

Hi all

I have a simple script for those of you who are not scared of a bit of Javascript, which works perfectly in IE, but fails in Firefox with the following error

Error: uncaught exception: [Exception... "Not enough arguments [nsIDOM3Node.getUserData]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame ::http://localhost:2690/AtlasAprilCTPTests/Default.aspx :: onclick :: line 1" data: no]

Here is the code, pretty simple stuff. Any ideas anyone?

<%@dotnet.itags.org.PageLanguage="C#"%>
<%@dotnet.itags.org.ImportNamespace="System.Web.Services" %>
<%@dotnet.itags.org.ImportNamespace="System.Data" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<atlas:ScriptManagerID="ScriptManager1"EnablePartialRendering="true"EnableScriptComponents="true"runat="server"/>
<scripttype="text/C#"runat="server">
[WebMethod]
publicDataTable getUsers()
{
DataSet1TableAdapters.tblUsersTableAdapter da =new DataSet1TableAdapters.tblUsersTableAdapter();
return da.GetData();
}
</script>
<scripttype="text/javascript">
function getUserData()
{
PageMethods.getUsers(reportData, reportTimeOut, reportError);
}
function reportData(result)
{
if(result)
{
var sb =new Array();
sb.push("<table border=1 style=\"border-collapse:collapse;\"><tr><td>UserID</td><td>Firstname</td><td>Surname</td><td>DOB</td><td>isSubscribed</td></tr>");
for(var i=0; i<result.get_length();i++)
{
sb.push("<tr><td>" + result.getItem(i).get_rowObject().UserID +"</td><td>" + result.getItem(i).get_rowObject().FirstName +"</td><td>" + result.getItem(i).get_rowObject().Surname +"</td><td>" + result.getItem(i).get_rowObject().DOB +"</td><td>" + result.getItem(i).get_rowObject().isSubscribed +"</td></tr>");
}
sb.push("</table>");
$("result").innerHTML = sb.join("");
}
}
function reportError(result)
{
alert(result);
}
function reportTimeOut(result)
{
alert(result);
}
</script>
</head>
<body>
<formid="form1"runat="server">
<div>
<inputtype="button"value="Get Table From DB"onclick="getUserData();"/>
</div>
<divid="result"></div>
</form>
</body>
</html>

Cheers

Martin

Hi Martin,

For some reason, it appears that Firefox doesn't like the name 'getUserData'. Rename it and it should all work. Maybe the name conflicts with a built-in Firefox function or something like that.

Maybe someone else can provide an explanation?

thanks,
David


Yes David is correct. Th problem is with getUserData which is a function defined in the DOM level 3 specification.

http://www.w3.org/TR/DOM-Level-3-Core/idl-definitions.html

The DOM function needs a parameter of type string. So if you rename the function it will work out.

Wednesday, March 21, 2012

Writing Games in ASP.NET AJAX

Hi All,

I was curious about usingAnimation behaviors in the toolkit to create games, but I found that they came up a bit short for this kind of task. So I wrote some behaviors and control extenders to allow sprite animation, collision detection, and some other fun stuff.

If you're interested in trying out this first version please check out thisblog post andproject page.

AndyBeaulieu:

Hi All,

I was curious about usingAnimation behaviors in the toolkit to create games, but I found that they came up a bit short for this kind of task. So I wrote some behaviors and control extenders to allow sprite animation, collision detection, and some other fun stuff.

If you're interested in trying out this first version please check out thisblog post andproject page.

That is so COOL! I am so trying this out... wonder if my bosses would let me put a shoot the fish game in our Government Applications.. you know... incase the customers get bored... could always bring back the amazing "Boss Key" :D

WYSIWYG-editor saying that a ScriptManager is not present when it is; throws an exception

Hey Guys,

I'm new to the AJAX Toolkit, so pardon me if my problem seems a bit dumb.

WYSIWYG Exception

As you can see in this image, I have a ScriptManager on the page, so I don't have a hot clue of what's really causing the problem. My HTML is all valid, and I can actually run the page through the built-in server and it works just fine.

Anyone have any ideas?

I'm not so sure but I think this could be caused by a wrong reference to the library that ajax uses (the Web.Extentions).

Try to remove the scriptmanager and just drag a new ScriptManager from the ToolBox to the top of the webpage. Then save the page, close it, and reopen it. Normally the design-view should render normally now.

I hope this helps!

Greets,
Wim

XML Script inside UpdatePanel: Not instantiated?

I have a bit of XML-Script (which assigns a Drag/Drop handle behavior to a control) that performs as expected. However, if I place this script inside an UpdatePanel then the script doesn't run. Is this a known issue? Any known workarounds? If not, can anyone provide me with insight on how the AJAX libraries identify and parse XML-script? E.g., Is there a function I can call that will reinitialize XML-Script blocks? Note: I can put a <script type="text/javascript" /> in an UpdatePanel and it'll execute as expected.

Jeremy

Bumping this thead. Any thoughts? Let me know if I need to clarify the request. The obvious work around is to just wire up the features using imperative syntax via Javascript, although this seems like a pretty obvious issue so I want to make sure I'm not missing something.


Can you please post the code you are using so I can take a look at it? Thanks


I later discovered that this functionality was by design and that any script (not just XML script) will not re-execute upon refresh of an UpdatePanel. There are a few work arounds posted for this on the internet which involve registering the script, probably via RegisterClientScriptBlock() or something similar. The approach didn't work for me, however, and I haven't had a chance to dive into this further yet. When I get a chance I will revisit this and post code samples and/or findings.

xmlHttp ajax issues

Hi all, totally baffled by this one!

I've got a bit of code:

xmlHttp.onreadystatechange=caravanSearchStateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
That fetches some html that's just been printed by an ASP page, and prints it to a div.

There's some code afterwards:

if (document.getElementById('hideHeaders').value == '1') {document.getElementById('resultsHeader').className = ' none';}else {document.getElementById('resultsHeader').className = 'floatleft paddingtop15';}
That checks a hidden HTML field for a 1 or a 0. If it's a 1, it hides a
div. If it's a 0, it shows a div. By default in the html, the field is
set to 0.

Trouble is, the if statement is delayed. If I want to hide that div, I
have to wait for the condition to get a 1 twice. Vice-versa for the 0.

However, if I put an alert saying "hello world!" between the two code snippets I gave you, it works!

It's almost as though the HTML is being written too late for the javascript to validate the if statement.

Trouble is, if I put a sleep function I found between those bits of code, it doesn't work.

What the hell is the problem here?

Any help's appreciated because I'm stuck!

Cheers,

Karl.

Hi,

The same problem is discussed athttp://forums.asp.net/p/1134520/1813795.aspx#1813795 &http://forums.asp.net/p/1134520/1813803.aspx#1813803

If yourHTML fieldis still not be shown,it is noneffective action at once to set the value of thefield.

The similar code in that post:

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button1_onclick() {
// This works

document.getElementById('div1').style.display = "block";
document.getElementById('div1').scrollLeft = 100;


// But this doesn't work

//document.getElementById('div1').scrollLeft = 100;
//document.getElementById('div1').style.display = "block";
}

// ]]>
</script>

Best Regards


Thanks for taking a look at that for me; I've since found a solution and have written a small blog about it so that people are aware.

If you have any questions, reply to this post and I'll have a go at answering them.Smile

http://codingrage.blogspot.com/2007/09/xmlhttprequest-object.html

Cheers,

Karl.