Showing posts with label functionality. Show all posts
Showing posts with label functionality. Show all posts

Monday, March 26, 2012

listbox ondblclick attribute

Hi

I am trying to invoke a listboxes double click attribute to utilize the Ajax.Net functionality.

I have a listbox in an UpdatePanel, and using the OnSelectedIndexChanged event I successfully perform client side actions using Ajax.
I now want to perform an action when a user double clicks on an item of the listbox. (remove this item)

I tried copying the OnSelectedIndexChanged attribute value generated by dot net and adding it through the code:

lbMyListBox.Attributes.Add("ondblclick","javascript:setTimeout('__doPostBack(\\'DoubleClick\\',\\'\\')', 0)");

This however keeps causing a page post back.
Is it possible to use the double click attribute?
I have searched everywhere without much luck

TIA

You will need to subclass the ListBox control and create the ondblclick event for postback usage... and remove the existing onSelectedIndexChanged event. This topic deals with fairly advanced .Net web control programming.

Here's an example that is quick and dirty... and does not fully take care of all possible scenarios.

public class MyListBox : ListBox, IPostBackEventHandler, IPostBackDataHandler {public event EventHandler OnDoubleClick;#region IPostBackEventHandler Membersvoid IPostBackEventHandler.RaisePostBackEvent(string eventArgument) {if (eventArgument =="ondblclick") {if (OnDoubleClick !=null)this.OnDoubleClick(this, EventArgs.Empty); } }#endregion protected override void OnPreRender(EventArgs e) {base.OnPreRender(e);this.Attributes.Add("ondblclick", Page.ClientScript.GetPostBackEventReference(this,"ondblclick")); }protected override void Render(HtmlTextWriter writer) {//Here we will remove the onchange event through string manipulation. StringWriter sw =new StringWriter(); HtmlTextWriter newWriter =new HtmlTextWriter(sw);base.Render(newWriter); sw.Flush();string html = sw.ToString();int indexofOnChg=html.IndexOf("onchange=\""); sw.Close(); html = html.Remove(indexofOnChg,html.IndexOf(" ", indexofOnChg) - indexofOnChg); writer.Write(html); } }

Thanks for your advice

Will give it a wirl

Listbox selections to update secondary listbox items

Good Afternoon,

I am extremely new to the Atlas functionality, and am trying to address some customer requests using Atlas. Two listboxes, Category and SubCategory, are initially rendered on the page with all distinct values. My question is how to update the SubCategory listbox when items have been selected in the Category listbox. I have tried to include a parameter for the selection of the SubCategory items, but the list initially is rendered with no items since the parameter value is not assigned.

Any help, insight, or suggestions is greatly appreciated. Also, any suggestions on best practices is also welcome regarding controls utilizing Atlas (for example, using a dataset to populate the listbox versus going directly against the SQL tables).

Thank you,

Erik

Hi,

It sounds like the CascadingDropDown control in this toolkit may be the answer to your questions.

http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx

Regards


Thank you for the response. Is there any way to utilize a listbox instead of a drop down? Currently, the users can select multiple items from the list.

Hi,

Could you initially populate the subcategory box in the page_load event (when not Page.Ispostback), then have the list updated with a control event parameter on the Category Listbox.

Hope this helps

ListView and xml-script no longer works in Beta 2

I used a MS example of databinding with an xml-script listview to get the functionality I needed and now with the Beta 2 the JS no longer works. Is anyone doing this in Beta 2? Read myoriginal post for more information (and code).FYI after 4 days I got the code to work. Seehttp://forums.asp.net/thread/1487186.aspx

Saturday, March 24, 2012

load page in div using ajax --> ajax functionality lost :s

Hi all,

I found some javascript on the net to load a page in a div. Now the problem is that the loading of the page in the div works, but then when I use ajax-functionality in the page loaded in the div, the page just refreshes.

Here I found the code:http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Here is a simular thread (his issue got resolved but mine not. On his site things seem to work just fine :s):http://forums.asp.net/t/1163067.aspx

Here is my working demo showing what goes wrong:

This is my situation:

    I have 2 pages: Default and Content.Default loads Content on it's page (using the "loading a page in a div"-logic)Content has basic ajax functionality which works from Content itself.Content's ajax func. won't work when it's loaded on Default.
The Default.aspx page (no codebehind to keep it simple):
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false"%><!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>Default</title><script type="text/javascript">var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)var loadedobjects=""var rootdomain="http://"+window.location.hostnamevar loadstatustext="<img src='img/loading.gif' /> Requesting content..."function ajaxpage(url, containerid){var page_request = falseif (window.XMLHttpRequest) // if Mozilla, Safari etcpage_request = new XMLHttpRequest()else if (window.ActiveXObject){ // if IEtry {page_request = new ActiveXObject("Msxml2.XMLHTTP")} catch (e){try{page_request = new ActiveXObject("Microsoft.XMLHTTP")}catch (e){}}}elsereturn falsepage_request.onreadystatechange=function(){loadpage(page_request, containerid)}page_request.open('GET', url, true)page_request.send(null)}function loadpage(page_request, containerid){if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))document.getElementById(containerid).innerHTML=page_request.responseText}function loadobjs(){if (!document.getElementById)returnfor (i=0; i<arguments.length; i++){var file=arguments[i]var fileref=""if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceedingif (file.indexOf(".js")!=-1){ //If object is a js filefileref=document.createElement('script')fileref.setAttribute("type","text/javascript");fileref.setAttribute("src", file);}else if (file.indexOf(".css")!=-1){ //If object is a css filefileref=document.createElement("link")fileref.setAttribute("rel", "stylesheet");fileref.setAttribute("type", "text/css");fileref.setAttribute("href", file);}}if (fileref!=""){document.getElementsByTagName("head").item(0).appendChild(fileref)loadedobjects+=file+" " //Remember this object as being already added to page}}}
</script></head><body> <form id="form1" runat="server"> </form> <p> <a href="javascript:ajaxpage('Content.aspx', 'contentarea');">test</a> </p><div id="contentarea"></div></body></html>

The Content.aspx page (also no codebehind to keep it simple):

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" %><script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadMe.Label1.Text = DateTime.Now.ToString End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)Me.Label1.Text = DateTime.Now.ToString End Sub</script><%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><!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>Content</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div><asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate><asp:Label ID="Label1" runat="server" Text="" Width="138px"></asp:Label><br /><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate></asp:UpdatePanel> </div> </form></body></html>

Could anyone please give it a try? I don't know what's going on.
The code above should work! Just make the 2 pages and copy the entire code into it.Thanks!

Kind regards,
Wim

My guess would be that your Content.aspx page contains some sort of window.onload event-handler to wire-up the Ajax stuff, but when you load in Content.aspx into Default.aspx using Ajax its window.onload event will not fire (the window.onload event will already have fired when Default.aspx was loaded).


ijoxley:

My guess would be that your Content.aspx page contains some sort of window.onload event-handler to wire-up the Ajax stuff, but when you load in Content.aspx into Default.aspx using Ajax its window.onload event will not fire (the window.onload event will already have fired when Default.aspx was loaded).

Hi ijoxley,

Thanks for your reply ...

But when I look at my code that's posted above, I don't see anything unusual happening in any onload event.


deblendewim:

But when I look at my code that's posted above, I don't see anything unusual happening in any onload event.

That's true - but its probably hidden away somewhere in the JavaScript generated by the ScriptManager tag.

It might be an idea to add a ScriptManager to the Default.aspx page then writing some JavaScript to handle the DOMNodeInserted event (for when you load Content.aspx into your <div> tag).


Anyone?


hello.i'm not sure on what you're trying to do here, but the approach you're using isnot the best to use if you're using asp.net ajax. ok, regarding your problem, i agree with the previous answeres you've received: the client portion of the asp.net ajax platform needs to run several pieces of code during the load event of the page. when you load a page like that, you're not getting that event and this means that your updatepanel won't be ready for patial postbacks.in my opinion, you should use only one page and if you need to change the contents of the page, then you can use one or more usercontrols to achieve that (instead of having several pages that are loaded into the center of your main page).