Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Wednesday, March 28, 2012

Change dropdown selectedvalue in usercontrol, in a page.aspx

Hello,

i have a usercontrol (reservas.ascx) with one dropdown list (dropHoteis) inserted in one masterPage.
In my default.aspx, that is a content page of that masterPage...
How can i change the selected value in the dropdown list (dropHoteis) from my default.aspx?

1. In reservas.ascx, i put the Class Public...
2. In Default.aspx.vb, how can i reference the reservas.ascx?? I tryed, but not appear in my @dotnet.itags.org.Imports... why?

Thanks for your help!

From the page you can useMe.Master.FindControl("IdOfUserControl") which will get you the reference to your user control.

-Damien


Hep, ok...

But in my UserControl how can i declare the "function/property" to change the selectedValue of the dropdownlist??

Example:

Public Property DropSelectedValue(ByVal hotelAs String)Set(ByVal value) dropHoteis.SelectedValue = valueEnd Set Get dropHoteis.SelectedValue = hotelReturn dropHoteis.SelectedIndexEnd Get End Property

This not work for me!! :(

throw: Object reference not set to an instance of an object!!


in the usercontrol's code behind write a public property in which you have to set the dropdown list's value. u can then access that property from your page.aspx using the usercontrol name and can set the value of the dropdown list.

Regards & have a nice day ahead

Monday, March 26, 2012

Catching an event from an Extender

I have written an extender and have everything working but catching an event in my .aspx page.

What is the recommended way for me to send a notification back to the application that something has happened in the extender and the page hosting the extender can take some action if it wants to?

I get the following alerts based on the code below

Client hooking into change -- at startup

add_changed -- at startup

raiseEvent: change -- when a change occurs

I have tried to use something like the following.

Control hookup in .aspx page

<psAjax:SampleExtender ID="sampleExtender" runat="server" TargetControlID="_tbName" Timeout = "250" BehaviorID="sampleExtenderBehavior"/>

Script in .aspx page

function linkBehavior()

{

var myBehavior = $find("sampleExtenderBehavior");

if (myBehavior)

{

myBehavior.add_changed(change);

}

}

function change () //This never fires

{

alert('aspx change');

}

Script in my extender .js file

add_changed : function(handler)

{

alert('add_changed');

this.get_events().addHandler('change', handler);

},

raiseEvent : function(eventName, eventArgs)

{

alert('raiseEvent: ' + eventName);

var handler = this.get_events().getHandler(eventName);

if (handler)

{

alert('Found raiseEvent: ' + eventName);

if (!eventArgs)

{

eventArgs = Sys.EventArgs.Empty;

}

handler(this, eventArgs);

}

},

I found my problem... I was not calling the linkBehavior method from pageLoad so a new behavior was created and destroyed when I called it.

I have since modified that approach and I am now registerting the event when a property is changed and this seems to work.

Is something like the following a valid way of doing things?

aspx code

<psAjax:TextChangedExtender ID="TextChangedExtender" runat="server" TargetControlID="_tbName" Timeout="250" TextChangedFunction = "onTextChanged" />

function onTextChanged()
{
alert('Client Side onTextChanged');
}


Extender .js

set_TextChangedFunction : function(value)
{
if (value != this.textChangedFunction)
{
this.remove_TextChangedHandler();

this.textChangedFunction = value;

var fn = new Function('return ' + this.textChangedFunction + '(); ');

this.add_textChanged(fn);

this.raisePropertyChanged('OnTextChanged');
}
},

Wednesday, March 21, 2012

CascadingDropDown Scenario!

Ok heres the deal, go the CascadingDropDown works on a simple aspx page but when I incorporate it into my MasterPages it fails with 12031 error code

Does the page has to derive from Page base class?

TIA

Hi,

Please make sure that the web method used by the cascadingDropDown can't be defined in masterpage, in this case, it can't be accessed from client side directly. Be sure to use a web service.

CascadingDropDown Memoryleak, something with ParentControlID?

Hi, I'm currently using two cacadingdropdown extenders which retrieves data from webmethods (no webservices) embedded in aspx page. One is the parent of the other. And now each time I refresh the memory increases 800-1000K at the time. But the strange thing is that if i remove the parent child relationship (no extender has parentcontrolid defined) the memory leaks do not accur.

Am I doings something wrong, is something missing in webconfig?

12<!--34-->5<configuration>6<appSettings/>7<connectionStrings>8<add name="UtstyrConnectionString" connectionString="Data Source=WIN2003STDBASE;Initial Catalog=Utstyr;Integrated Security=True" providerName="System.Data.SqlClient"/>9</connectionStrings>10<system.web>11<pages enableEventValidation="false"></pages>1213<compilation debug="true">14<assemblies>15<add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>16<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>1718<authentication mode="Windows"/>19 <identity impersonate="true"/>20 <authorization>21 <allow users="*"/>22 </authorization>23<httpHandlers>24<remove verb="*" path="*.asmx"/>25<add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>26<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>27</httpHandlers>28<httpModules>29<add name="WebResourceCompression" type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>30<add name="ScriptModule" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>31</httpModules>32</system.web>33</configuration>

Cheers GauteO

PS both my dropdownboxes and cacadingdropdownextenders are in an updatepanel

Here is a simple sample of what I mean. If anybody could run this to determine if it is a internal problem.

1<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>2<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>3<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"4 Namespace="Microsoft.Web.UI" TagPrefix="asp" %>5<script runat="server">6 [System.Web.Services.WebMethod]7 [Microsoft.Web.Script.Services.ScriptMethod()]8 public static AjaxControlToolkit.CascadingDropDownNameValue[] Get(string knownCategoryValues, string category)9 {10 int count = 5;11 AjaxControlToolkit.CascadingDropDownNameValue[] cddnv = new AjaxControlToolkit.CascadingDropDownNameValue[count];12 for (int i = 0; i < count; i++)13 cddnv[i] = new AjaxControlToolkit.CascadingDropDownNameValue("Gaute" + i, i.ToString());14 return cddnv;15 }16 </script>17<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">18<html xmlns="http://www.w3.org/1999/xhtml" >19<head runat="server">20 <title>Untitled Page</title>21</head>22<body>23 <form id="form1" runat="server">24 <div>25 <asp:ScriptManager ID="ScriptManager1" runat="server">26 </asp:ScriptManager>27 <asp:DropDownList ID="DropDownList1" runat="server">28 </asp:DropDownList>29 <asp:DropDownList ID="DropDownList2" runat="server">30 </asp:DropDownList>31 <cc2:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="Valg" LoadingText="Laster" PromptText="Velg" ServiceMethod="Get" TargetControlID="DropDownList1">32 </cc2:CascadingDropDown>33 <cc2:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="Velger" LoadingText="Laster" PromptText="Velg" ServiceMethod="Get" TargetControlID="DropDownList2" ParentControlID="DropDownList1">34 </cc2:CascadingDropDown>35 </div>36 </form>37</body>38</html>

This code gives me a memory leak of 700-1000k each time the page posts back. And if I remove the ParentControlId from CacadingDropDown2 (line 33) the memomry leaks stops. Testet the samplewebsite in ajaxtoolkit (cacadingdropdown) and that didn't have the memoryleaks. I have tried to elumate(copy) the procedure in the site, but cant stop the leaks.

GauteO


*bump*

also tried with RC1 release, same problem..


What Browser are you testing with? Or is this problem occuring in all browsers?

The reason I ask, is that I found that several issues with the CascadingDropDowns disappeared when I moved to IE 7.0. For example, with IE 6.x I have found that having two different sets of CascadingDropDowns on the same page will break the functionality of the SelectedValue tags... Only the first set of CascadingDropDowns will get the correct initial value...


Currently I have only testet with ie6, I shall test on other browser when I get to work again (as I'm currently home). I usally test in opera, firefox, ie6 and ie7+(vista browser). But I am really cursious if anybody else get this memory leak when one of the cascadingdropdown extenderes has an parentcontrolid assign to it, and stops when none have an parentcontrolid. They provide/retrieves the same information in both instances, only diffrence that the cacadingdropdown with parentcontrolid has the "knownvalues" of its parent (and 700-1000k is pretty much for 5 values beeing sent, as in the sample in the second post). Maybe I must embed the information in XML (as they do in the sample site ajaxcontrolkit)?

Hmm, I have testet the scenario on opera and ie7+ and the memory leaks do not accur. I also testet the sitehttp://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspx again, with ie6, and the memory leak problem accurs there too (was sure that I tested this before and didn't have the problem, it was beta2 not rc1 which I testet now). It seems that ie6 is the problem, I am running 2003 server on a virtual pc(vmware), but it does not have the latest updates (trying to install them, but windows update just stops). Maybe this problem only accurs on old versions of ie6 (IE that follows a clean install of 2003 server), if anybody could confirm this it would be of great help (use the cacadingdropdown example on the ajaxcontrolkit website). My current version of ie6 is:

GauteO


That this doesn't happen in other browsers (including IE7) suggests to me that it's probably not something the Toolkit is doing wrong. Please let us know what happens with an updated IE6.