Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, March 28, 2012

multiple updatepanel which one is actived javascript

Hi all,

Title says everthing actually. I need to find which update panel is updating at the moment for multiple update panel coding which in one update panel i have coded to update others on the server side conditionally. If i cant find which one is activated is it possible to find which one initiated the update will work too. Thanks

Hi.

You can use UpdateProgress and associated the update panel with AssociatedUpdatePanelID property .

Hopes that help.


If I understand you correctly, you want to know on the client which UpdatePanel(s) were just updated.

If that's right, then take a look at the PageLoaded event on the PageRequestManager:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx.

You'll get two parameters passed to your handler... the second is a PageLoadedEventArgs:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageLoadedEventArgsClass/default.aspx.

You can use args.get_panelsUpdated() to get an array of <div> elements that were just updated during an async postback.


actually both answers are not what I'm looking for if i read correctly. First i don't have UpdateProgress i use an generic modal that's called all over the place with out caller information. Its a function that shows please wait message like pleasewait(true); or false soAssociatedUpdatePanelID wont work since i don't have one.

And for your suggestion if i read this right, it works right after the update is ended, I need it while its working so i know if i want to abort it or not. Since one of the update is crucial not to stop, one is not crucial. So when i give them option to stop it should only stop if its not crucial. (if that make sense)

Im not sure but im going to try to set an hidden field with a value right when the update starts but didnt have time to test this one yet.


So you're looking to see what control is causing the update? (As opposed to which panels will be updated.)


no no i am look looking for which update panel is getting updated but i need to know it before or while the server side is getting called, like lets say we have updatepanel1, panel2 and panel3

they all call pleasewait(true) function to start the please wait modal window

I show a cancel button here but i only want this cancel button to work for updatepanel1 so need is it the panel one activing the please wait or panel2 or 3, so using the info i can disable the cancel button.

I hope that make sense.


But from your first post, aren't you making the decision about which UpdatePanels to update on the server? If so, there's no way to know on the client which panels will be updated, since that hasn't been decided yet.

In general, even if you're not doing anything explicit on the server (just using Triggers), all you can know on the client is which control is posting back. You won't know until the postback finishes which panels actually get updated.


Steve Marx:

But from your first post, aren't you making the decision about which UpdatePanels to update on the server? If so, there's no way to know on the client which panels will be updated, since that hasn't been decided yet.

Thats ok, i tought it would be the same tooo. So is possible to tell the second part of my question

drewex:

If i cant find which one is activated is it possible to find which one initiated the update will work too

As long as i can find which one initiates the update i think i can make this work.


I'll add one more thing there are iframes that i use in this page which can call the please wait too. So i need to seperate those too. But if there is not updatepanel update initiated that means iframe called it. so i can give cancel option or not. I hope im making some sense.

Monday, March 26, 2012

Multiview and Javascript in a view.

Hi, I am using a Multiview control in an update panel, and I need to output some dynamic Javascript inside a View control. Please see below.

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="478px" Width="557px">
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">


</asp:View>
<asp:View ID="View2" runat="server">

<script type="text/Javascript">//<![CDATA[
function aa(){alert('<%= DateTime.Now %>');}
//]]></script>
<input type='button' onclick='aa()' />

</asp:View>
</asp:MultiView>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

--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;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}
}

The problem is, that when you click the button that runs the function "aa", an "Object expected" error is thrown. Presumably because the newly outputted script has not been 'registered' with the browser (I checked with Nikhils Web Dev Helper and the script is present).

As I say, the script is dynamic, so I can't move it to an external file, nor would it be good to have to write the script outside of the Multiview (since it's dependent on the controls in View).

Any help or tips greatly welcome - thanks,

Jim


Read this, will give you solution.

http://forums.asp.net/thread/1502486.aspx

WS


Thanks, that did help with my example -however...

In reality my UpdatePanel and Multiview are inside a UserControl. So I dont have access to ScriptManager from the UserControl.

I looked at ScriptManagerProxy, but that doesn't have the RegisterClientScriptBlock method :(

Any idea how I can do this from within a UserControl?

Many thanks

Jim


Is this your code behind from your UserControl?

protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}

??

You can add

protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
System.Web.UI.ScriptManager.RegisterClientScriptBlock ...
}

It works on my end ... should be the same on yours.

WS


AHH! RegisterClientScriptBlock is static - sorry I assumed it wasn't.

Yes that works great, thanks very much - you saved me some awkward workarounds.

Smile

Jim


Can I open up this topic, and add a little twist to it?

I have u panel inside a multiview, this panel has a usercontrol which shows a HTML page from a database (response.binarywrite because it's all blobs) I hav e NO control of the javascript that is used in the HTML files that are loaded from the database.

One of the HTML files that is loaded, contains javascript to have a menu with hoverfunctions enabled on the html-page:

if (window.attachEvent) window.attachEvent("onload", sfHover);

When I switch the multiview.activeindex, back and forth to the panel with the usercontrol, the hover functions do not work anymore...anyway, in IE they don't. In Firefox they do work.

The RegisterClientScriptBlock is no option, because I am not aware of the javascript functions that are used in the database-files.

I hope my explanation is clear...

Rob

Mutex + Javascript in AJAX rtm?

Hello all -

Would be nice to see mutex implemented natively in AJAX before RTM. Personally I think a lot of poll/update style applications would greatly benefit from this being included directly in the Client FX as I do not see most developers going out of their way to implement this own their own. Here's a nice article on the matter. http://www.developer.com/lang/jscript/article.php/3592016

PS: Are javascript apps getting way too complex? I don't know if I like the words mutex and javascript used in the same sentence.

PPS: Sorry for posting in two forums but networking forum doesn't get much attention.

AO

IMHO, we don't need mutexes in JavaScript, and while the article you link is very interesting, I find it conceptually broken, because JS is not an OO language, neither it is concurrent.

JS is rather "event-driven", and one should know about the timing issues involved, and how these can be solved with a simple flag, rather than writing 10000 lines of (client-side) code to queue what's already queued by the runtime.

To be true, I do not like this very new trend about making OO frameworks out of JS at all, including the design underlying the Asp.Net Ajax framework itself. That is, frameworks where the few is functionality, the most is wrapping a language from its natural paradigm to a foreign one. For this, I would link an article from one of the fathers of the JS language:

JavaScript: The Wrrrld's Most Misunderstood Programming Language

Hope this helps. -LV


Julio - I totally agree with you but the fact remains that browser's do not implement the JS spec faithfully. If you do some testing on different browsers you will find that functions can be called in parallel. Try testing an alert function call (that blocks until it returns) and using an HTR object, you will find that the functions are started in parallel. In my opinion I would sleep more comfortably if I didn't have to implement language hacks such as mutex in Javascript but it seems to me that while we're interacting with native JS objects the single thread paradigm is kept but once we start interacting with browser objects then all bets are off. I realize mutex won't be required in most scenarios but in a few I think they may be necessary...

As for your event-driven comment I am not sure what you mean by a simple flag, maybe you can elaborate? What I think you mean is while(isProcessing) { a = a + 1; }? This would eat up 100% cpu... and is essentially the bakery algorithm that is used in the linked implementation.

Has anyone else experimented with this?


aosipov:

Julio - I totally agree with you but the fact remains that browser's do not implement the JS spec faithfully.

I am too used to work around browsers limitations since the Web has born. That has never required writing 10000 lines of code for - what?

aosipov:

If you do some testing on different browsers you will find that functions can be called in parallel. Try testing an alert function call (that blocks until it returns) and using an HTR object, you will find that the functions are started in parallel.

AFAIK, this is simply not the case. When you callalert, you force the browser to play all events in the queue, in order to synchronize the interface. That's known and documented behavior that all the browsers I am aware of do implement. And, it still is NOT concurrent: events get fired in sequence! That's why a flag ("a boolean value") is enough: there simply is NO concurrency in JavaScript.

This said, I'd be glad to see a practical sample reproducing this "problem", given that not even the author of the mentioned article has provided one...

-LV


For reference, I'll give a sample about where a timing issue can occur and how easy it is to prevent any problem in idiomatic JS.

The full source is here:http://forums.asp.net/ShowPost.aspx?PostID=1456947

Once you have got what that does, just focus on this simple fragment:

// Keep order!
fileDsp.innerHTML = "<em>Loading...</em>";

fileImg.src = fileBox.value;
//

Since this code is loading a local file*, assigning to the src property of the image immediately triggers the onload event for the image. But assigning to the innerHTML property too enqueues an interface update. Bottom line, if you revert the order of the statements above, you do not get correct results, because the sequence in which you enqueue events is the sequence in which they get then run!!!

And, this is true for JS in web pages as well as it is true for any ECMA-based language, like it was JS in VRML, like it is AS in Flash, and so on.

I hope this can shed a bit more light, anyway if you guys have any significant sample that you would like to see analyzed and refactored to "true" JS, please don't be shy and post it. IMHO, it might be a very instructive "case-study" for everybody trying to find their way with client-side programming.

-LV

*If the file was not local, the timing issue involvedmightnot show up. Yet, that is the way to go in general, for robust JS programming... We don't need mutexes, neither we miss OO-JS. We better simply know our language...


Oh yeah: BTW, thefileRefvariable you can see there is a perfect instance of the "flags" I was talking about above.

-LV


Hi again LV - I am glad someone is interested in figuring this out with me.

Here's a simple example where I think a Mutex implementation may be necessary. Create the following page and then launch in IE (make sure to allow popups and not using tabs for new windows!).

<html><head><title>My test page</title></head><body><script type="text/javascript">var o = window.opener;function changeParentValueInParallel() { if (o && !o.closed) { o.changeValue('b'); alert('Parent property changed'); }}window.MyProperty = 'a';if (!(o && !o.closed)) { window.changeValue = function(v) { window.MyProperty = v; } window.open(window.location); alert('Stage pre change parent window.MyProperty: ' + window.MyProperty + '\n\n' + 'Before clicking OK press the Click me button in the child window'); alert('Stage post change parent window.MyProperty: ' + window.MyProperty);}</script><input type="button" name="invoke" onclick="changeParentValueInParallel();" value="Click me"/></body></html>

Here are the steps to reproducing the concurrency. Open the page, then on the parent page there will be an alert - DO NOT CLICK OK, go into the newly opened page (child) and click the button. Then click OK on the parent page. What you will see in IE and Opera (FF behaves in what I consider to be correct behavior) is the parent's window value be changed by the child while I am still in the function. Alas, this is exactly what parallel execution is, and thus the need for mutex (or some other mechanism). I don't think I have to explain how this can damage code, this is fairly standard textbook.

It is my guestimate that the XTR objects and ActiveX behave the same way in IE as well as Opera (does anyone have access to Safari at the moment to test this).

Julio, I am not sure how a simple flag would be able to help here. Would love to know what other ways other than mutex implementation would work here to prevent this sort of thing in critical sections. By the way, the mutex implementation is only 30 lines (not 10,000 as you say).

Everyone, please chime in here this is fairly important (I think).

Alex


aosipov:

Here's a simple example where I think a Mutex implementation may be necessary.

I'm afraid your sample is not very much significant. Apart from the fact that it is quite far from any real life code, the basic problem is that - as said before - in JS the "sequence" of the messages is what matters, and you have actually messed that up, so that it can't but misbehave... you wrote it to do it! (E.g. you call "before" what you are really executing "after", and you try to get results from the same opening method, while you should really do that from the popup *after* the popup has finished...)

aosipov:

By the way, the mutex implementation is only 30 lines (not 10,000 as you say).

10000 stands for far-too-many, and I was talking about the client-side frameworks in general there.

-LV


This was a proof of concept in the most simple example that I could make without adding complexity of a real world application. I have experienced similar problems (concurrency based) in real world applications but I cannot post this code nor would anyone examine it. To get back to the real problem, with asynchronous callbacks I cannot control the sequence of events (at least in IE and Opera) and cannot guaruantee that a function will not run concurrently. This is not a problem for me as my code is already ready for such guaranteeing critical sections and critical data are locked during execution. The point of this post was to get Atlas/AJAX team to recognize that a problem exists and possibly get a generic solution included in AJAX so we don't have to roll out our own custom solutions. This seems to be a general enough problem that a lot of programming languages or standard libraries include mechanisms to work around it and it seems reasonable for AJAX as a client side library to provide a similar mechanism. I could be wrong but I am pretty sure my example shows the fundamental problem (of course not in a real world scenario).

Am I on crazy pills? I would love not to have to resort to such complexity in javascript if someone can explain to me a viable alternative to guarantee my global memory will not be corrupted/modified concurrently. Please help!

Alex


aosipov:

I cannot control the sequence of events (at least in IE and Opera) and cannot guaruantee that a function will not run concurrently.

Not only you can control the sequence of events, but - again - there simply is NO CONCURRENCY in JS.

The basic problem (IMHO) is that you are mixing concepts from other languages completely different from the JS and its runtime model. That's why I am basically only stressing that you should know your language, rather than ask for foreign constructs you are more familiar with. Those constructs simply do not apply here!*

aosipov:

I could be wrong but I am pretty sure my example shows the fundamental problem (of course not in a real world scenario).

The code above is simply wrong. It misbehaves because you have written it so that it cannot but misbehave...

aosipov:

Am I on crazy pills?

Incorrect is not crazy, and I appreciate your efforts to get deeper.

So, now I'll stop and wait with you for more feedback, in case anybody has something to add.

-LV

*With an analogy: var x = "2" + "2" not giving back 4 doesn't imply - say - that JS lacks operator overloading, it would rather imply the programmer doesn't know what (s)he is doing...


LudovicoVan:


Not only you can control the sequence of events, but - again - there simply is NO CONCURRENCY in JS.

What is my example then? Here's a definition out of Wikipedia "Concurrency occurs when two or more execution flows are able to run simultaneously." What am I missing?

LudovicoVan:


The basic problem (IMHO) is that you are mixing concepts from other languages completely different from the JS and its runtime model. That's why I am basically only stressing that you should know your language, rather than ask for foreign constructs you are more familiar with. Those constructs simply do not apply here!


To guarantee atomicity I use a mutex. This is a concept that applies to languages that are able to execute flows simultaneously. Javascript may not be such a language and I am not agruing that it is. The implemention of Javascript in IE and Opera (but NOT FIREFOX) allows for parallel execution and thus arises my need for concurrency control. The IE and Opera javascript runtime model (to use your words) allows for concurrency as demonstrated by my example (I am sure this was a design decision to allow faster rendering). In a perfect world, Javascript would be single threaded and would lock the window global object to updates until the current code is finished executing - this would guarantee a safe environment where no race conditions can occur. This is what Firefox does. To restate again, this is NOT the case in IE and Firefox. Therefore I need to guarantee some of my updates are atomic and therefore I use mutex implementation.

LudovicoVan:


The code above is simply wrong. It misbehaves because you have written it so that it cannot but misbehave...


Like I said previous, this example was a demonstration of concurrency showing the base problem (in the simplest way I could think of). I can repeat the same behavior with asynchronous callbacks, that is I can make a request that calls one of my callback functions in parallel to another function executing. The reason I made this example is because it is much easier to catch because there is no timing involved and I can control the timing myself and preproduce the problem every time, rarther than reproducing the problem under certain circumstances that are hard to simulate in an example (if not impossible w/o extensive retries).

I am not sure how I am incorrect here. LV, I too appreciate your effort to uncover the real needs here!!! I understand your point that javascript doesn't have concurrency but in the real world of browsers we must work around different implementations so I am looking for the best way to do this and possibly get this included in a standard framework (AJAX). This is pretty important.


I think it may appear that there is concurrency when in fact there isn't... when an Alert is open, the browser may divide the code into seperate tasks, and there are situations where other code may run while the original alert is open. But without the alert there could not be any concurrency. Basically using alert to try and prove concurrency isn't going to work. You can get multiple paths through the same code using this trick but only if you introduce an alert -- it cant happen otherwise.
I have seen this same problem w/o using alerts but with XTR callbacks.

aosipov:

What is my example then? Here's a definition out of Wikipedia "Concurrency occurs when two or more execution flows are able to run simultaneously." What am I missing?

JS is not concurrent, that is you never ever have two paths of execution running at the same time in the context of the same host (in our case, a browser's window). What you get is incorrect sequence of execution, not concurrent execution.

aosipov:

Like I said previous, this example was a demonstration of concurrency

Again, it is not concurrent. It just shows a messed-up flow.

aosipov:

I can repeat the same behavior with asynchronous callbacks, that is I can make a request that calls one of my callback functions in parallel to another function executing.

This should simply not be the case, so maybe post a sample...

In the meantime I'll tell you that this approach would mess the flow up:

// Which runs first?
StartHttpRequest(httpCallback);
StartTimer(timerCallback, 2000);
function httpCallback() { doSomethingFirst(); }
function timerCallback() { doSomethingAfter(); }

This approach instead would work reliably:

StartHttpRequest(httpCallback);
function httpCallback() { doSomethingFirst(); doSomethingAfter(); }

There is no concurrency, it is a matter of "sequence". -LV


Hello back, here is maybe a more significant example.

Say we have to issue two server calls returning an integer, then get the sum of the two integers and use that in a third function. We are not guaranteed the order of execution for the two callbacks, neither we actually know when they are going to return a value at all. How we could "architect" this? Here is some code, not perfect because it still is a generic sample, so no point in "optimizing", yet should give some hints:

var cbCount, cbValue1, cbValue2;

// Whatever the timing, these two callbacks
// won't run concurrently, so no need
// for a synchronization mechanism
function httpCallback1(v) {
cbValue1 = parseInt(v, 10);
if(++cbCount == 2) finishProcess();
}
function httpCallback2(v) {
cbValue2 = parseInt(v, 10);
if(++cbCount == 2) finishProcess();
}

function startProcess() {
cbCount = 0;
startHttpReq1(httpCallback1);
startHttpReq2(httpCallback2);
}

function finishProcess() {
var sum = cbValue1 + cbValue2;
alert(sum);
}

startProcess();

A bit improperly, anyway here we might think of the cbCount as a "semaphore".

Hope this can shed more light. (Does it?) -LV

Saturday, March 24, 2012

my javascript method not working with update panel

Hi All,

The gridview (inside a user control) i am using in my screen (.aspx page) have a Checkbox column in the end. When i click the checkbox in the header all the checkboxes are selected. (A long javascript code has been written for that in the user control)

Now I have applied a scriptmanager and update Panel on this user control, and since then the javascript which selects all the checkboxes is not working properly.

I would like to know what i can do to resolve this javascript issue. And also would like to know why using the basic tools of ASP.NET AJAX control is stopping my own javascript from firing.

Please Note: On leaving a validation on page, the page postback and shows the validation. After this the javascript of Gridview works fine.

I have tried searching on google, but was not able to find any satisfactory explanation to my problem. It would be great if you people can help me.

Thanks,

Shikha

Please post your source code.


Hi,

Thank you for your post!

It is normal when you place inline javascript in an undatepanel/

For more information and solution, seeUpdatePanel and Rendered (Inline)Javascript

It seems that the UpdatePanel essentially replaces the InnerHTML of a DIV with the delta returned from the server. If you try this yourself you will notice that any javascript elements in the html are not fired.

All javascript registered on the server-side (if you are using .NET) with the ScriptManager is put into a separate section of the returned delta. The atlas runtime obviously then loads these scripts into the document manually.

What if the returned HTML has Javascript tags already rendered in it? Nothing.:(
Such was our predicament and we had no control over the HTML that would be returned to the UpdatePanel (ReportViewer Control). Could we manually load the javascript ourselves when the UpdatePanel returns the payload? As it turns, we could.

You can create script elements on the fly and they get evaluated as you do. Atlas has the ScriptLoader object that will do it for you if your JavaScript is an external reference. Tweaking this idea we got a solution that found all the new Script elements and added them to the document.

If you have further questions,let me know.

Best Regards,

Namespace for client side Postbacks

Does anybody know what the Ajax namespace for implementing a clientside (javascript) postback is? Ideally I would like to fire a partial postback event to an update panel, pass in some arguements and then capture the event in the codebehind.Did you ever find an answer to your question? I've been looking for the same thing without any success. Every example I find is all about doing things on the client side nothing about the server side using .Net AJAX.

nope. It seems that there is no direct method to call a postback from JS. I find people asking for it all over the place though, so I would hope that MS includes it in the next version.

The work around is pretty good though. You basically have two options, I use option #1.

1) Set a hidden field as a trigger. Through JavaScript, update the value of the hidden field. This causes the Ajax postback as desired.

2) I have read about people placing a "submit" button in a hidden DIV and setting that as the trigger. Again, you submit the button via JS.

Let me know if you get stuck and I can send you code.


Thanks for your reply, actually I'm trying to write a control that uses the UpdatePanel. I wrap my control in it and I've tried adding some buttons to the triggers collection, but when I click the button it performs a normal postback. Is there anything special you've found that needs to be done for something like this to cause an ajax postback? What I'm doing here sounds kind of like your second suggestion, but it doesn't seem to work.

Anything INSIDE an Update panel should cause only an "Ajax" postback, and that includes other controls. Make sure you have the attribute Updatemode set to conditional. Like so:

<

asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional">

Wednesday, March 21, 2012

Need help getting javascript widget to work

I'm trying to get the following to work in my ASP .NET AJAX site:

dhtmlGoodies xpPane

I'd like to use it as a main menu for my site, so this is what my masterpage looks like:

<%@dotnet.itags.org. Master Language="C#" AutoEventWireup="true" CodeFile="Blah.master.cs" Inherits="Blah" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link runat="server" type="text/css" rel="stylesheet" id="cssLink" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="/Blah/scripts/xpPane.js" />
</Scripts>
</asp:ScriptManager>
<div id="dhtmlgoodies_xpPane">
<div class="dhtmlgoodies_panel>">
<div>
<!-- Start content of pane --> Testing...<br />
Test 1<br />
Test 2<br />
Test 3
<!-- End content --> </div>
</div>
</div>
<script type="text/javascript">initDhtmlgoodies_xpPane(Array('Test Title'), Array(true), Array());</script>
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

I've seperated the the javascript and css and put them in their own files. I've also put the required images into /Blah/scripts/images/. I added the following to the end of the javascript file:

if (typeof(Sys) !=='undefined'){
Sys.Application.notifyScriptLoaded();
alert("Howdy! I'm an external file.");
}

When I view the page all I see isthis

I do not get any script errors on the page. Also the javascript alert I put in is being shown, so the script is definately being loaded. Any help would be much appreciated! Smile

Hello, i am actually dont know what are you tryting to accomplish from your post. but if you are trying to do the menus. Then just use ASP .NET menu control.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/navigation/default.aspx

and here is a great video about it:

http://asp.net/learn/videos/view.aspx?tabid=63&id=48


Is there no one here that can get this thing to work? Surely its possible...

Replace " <div class="dhtmlgoodies_panel>">"

with

<div class="dhtmlgoodies_panel">
!

You are so careless!!!!!


I must've read over that line 100 times without noticing the out-of-place angle bracket. Its not so much about carelessness - sometimes it just takes another pair of eyesWink


Thanks for pointing it out, I'll try it later and let you know if it works!!


I've tested it,and found that it worked very well:)

Do you have any question?


Yup it works fine now. Thanks for the help!Big Smile

Need help with sliders.

I am trying to use some sliders in an ajax page with javascript. What is the difference between the "TargetControlID" and the "BoundControlID"? In each instance, I put in a label, a textbox, and a slider. I expect to see the label followed by the text box, with the slider on the next line. The slider should control the value in the text box. I set the slider's "Target" control to be the textbox. When I run the page, the text box was missing.

Then I tried putting two text boxes after the label, making one of them the "Target" control and one of them the "Bound" control. This time I see only one textbox, and it displays values as I move the slider. But I'm not sure which one I'm seeing. This text box is now below the slider instead of above it next to the label.

There are four of these slider/label/textbox combinations in my page. I want the numeric values to be accessible on both the VB.Net server side, and the Javascript client side. I assume I should read the value from one of the text boxes.

Another problem I notice is that the slider does not "stick" to the mouse pointer like I expect it to. It "jumps" to the right when I push the button down, and jumps back to the left when I release. The value displayed changes the same way.

Hi,

the TargetControlID property must be set to the ID of the TextBox that you want to become the slider. The BoundControlID property must be set to the ID of a control (a TextBox or a Label) that displays the slider's value in real time.

The SliderExtender turns a TextBox into a slider, this is the reason why the extended textbox is disappearing.

If you want to access the value of the slider on the server side, this is returned by the Text property of the extended TextBox control.

Quick example:

<%@. Page Language="C#" %><%@. Register Namespace="AjaxControlToolkit" Assembly="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></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager> <div> <asp:TextBox ID="Slider1" runat="server">50</asp:TextBox> <asp:Label ID="Label1" runat="server"></asp:Label> <ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="Slider1" BoundControlID="Label1"></ajaxToolkit:SliderExtender> </div> </form></body></html>

I still have problems with the slider handle following the mouse properly.

Also, this being an ajax application with javascript using callbacks, I cant get the server code to read any changes to my sliders, text boxes, check boxes, or radio buttons. They still read as their initial values. In fact, if I put server side event handlers on them, the change events don't get handled. Everything works on the client side.

I tried putting them all in an update panel triggered by all of them, but that didn't help.


Hi,

regarding the handle: the slider has been programmed against the ASP.NET AJAX drag and drop engine. Since the engine doesn't support horizontal or vertical drag, we have used a trick (an invisible handle) to make it work. This is why the handle doesn't follow the mouse as you describe. However, this is very likely to change in the next releases of the Ajax Control Toolkit.

Regarding the changes in the values of controls. The following example is a slight variation on the previous one. Note that the extended textbox (the slider) has AutoPostBack="true". Therefore, it will post back to the server whenever you change the slider's value. On the server side, the new value is used to update the label's text. This demonstrates that the TextChanged event is fired and that you can access the updated value on the server side.

<%@. Page Language="C#" %><%@. Register Namespace="AjaxControlToolkit" Assembly="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"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Label1.Text = Slider1.Text.ToString(); } } protected void Slider1_TextChanged(object sender, EventArgs e) { Label1.Text = Slider1.Text.ToString(); } </script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="Slider1" runat="server" AutoPostBack="true" OnTextChanged="Slider1_TextChanged">50</asp:TextBox> <asp:Label ID="Label1" runat="server"></asp:Label> <ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="Slider1" Steps="3"></ajaxToolkit:SliderExtender> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Need Opinion

Hello all, =)

I have question(s) regarding the way I add JavaScript functions and I need opinion(s). Here's one of my example:

HTML:
...
<asp:TextBox ID="txtUserName" MaxLength="30" runat="server" />
<asp:Button ID="btnAddUser" Text="Add User" OnClientClick="return ValidateUser();" OnClick="AddUser" runat="server" /
Code Behind:
protected void Page_Load(object sender, eventargs e)
{
LoadMy_JavaScripts();
}

private void LoadMy_JavaScripts()
{
string script = "";
script += "function ValidateUser()";
script += "{ ";
script += " do something here ...";
script += "}";

System.Web.UI.ScriptManager.RegisterClientScriptBlock( ... ... );
}

As you can see how I register my javascript functions. Most my pages, LoadMy_JavaScripts() contains more than 20+ javascript functions. Every time when there's a postback (partial or not), this LoadMy_JavaScritps() is called again. I have developed more than 100+ pages of .aspx with ajax and all of them are working fine with the way I am doing.

Now I am wondering if what I am doing is right or not. I know that I can add the .js file directly to the ScriptManager using ScriptReference.

from the example above: if i move that ValidateUser function into a .js file, when should i add the .js file to the scriptmanager? Is it at Page_Load? I do not want to add it directly to the <asp:ScriptManager ... > because other pages do not use this function.

Any feedback/opinion would be sweet ... ta ta ...

The 'best practice' on this is to put all your .js in a separate file (or files as needed) and then add them as scriptreferences. THis makes them easier to control and maintain, lets your clients' browsers cache the information, stops you from having to resend the same stuff on every page_load, and so on.

If your scriptmanager is on a Master page (as you indicate) then you use a scriptmanagerproxy on the content page to load additional page-specific script files. ALternatively, you can add a scriptreference programmatically if you want. Embedding javascript in your codefile is a lot more prone to error, no matter how good you are it's easy to forget to add an important syntax bit when you're doing string concatenation.

As a sidenote, when you must concatenate strings, it's almost always a good deal more efficient to use the a StringBuilder object than it is to do += style string concatenation.


Paul,

thanks again, ... i don't have any problem with string concat. =) ... javascript is easy to debug anyway.

Thanks for your input ... before i used to add the javascript druing databound later on i moved everything to a function as i am doing right now. I guess I'll start storing them in a .js file. It makes more sense ... ... =)


Anytime; glad to help. FWIW, I used to do string concat that way too until I heard about the performance hit, which I gather can be pretty signficant if there are enough concatenations.