Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Wednesday, March 28, 2012

Change Event not fired when changed once or more then restored to its original value.

Hi.


I am trying to ATLAS-ize an existing application with lots of Master Detail controls.

As I don't want to write a heap of new code I am using UpdatePanels rather than writing web services even though my situation is similar to the one in the CascadingDropDown example (http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx)


The problem I have though is that if I change the master listbox selected value (say from 0 to 1) then the Update Panel refreshes fine.

If I change it back from 1 to 0 the SelectedIndexChanged event does not fire leaving a load of incompatible info in the details listbox

I'm assuming that this is because when the page was first loaded the value was 0 so it does not recognize that a change has occurred.

I'd be grateful for advice on the optimum solution to this.

Ah Problem Semi Solved!


The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)

The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)


Ah Problem Semi Solved!


The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)

The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)


Your drop down list is set to do a autopostback, correct? This would translate to a partial postback given that it's within the update panel.

Given that you've turned off the standard viewstate mechanism provided by ASP.Net, the "change" isn't going to be noticed 'cause the runtime can't compare what "was" (in the viewstate) with what "is" (in the form post). However, you can...

Take a look at this Fiddler trace of a site I quickly built using the update panel to do what you're doing with a drop down list (this is taken when the drop-down list auto posts back to the server):

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 305
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=DropDownList1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUKLTgwNzIyNjA5NA9kFgICAw9kFgICAw9kFgJmD2QWAgIDDxBkZBYBZmRkrJaJXj2KU%2FOTLiUUKLu7RDDJunM%3D&DropDownList1=2&__EVENTVALIDATION=%2FwEWBALyq5BnAp3kj%2BUKApKLpYsGApOLpYsGRIPIbgqWzDqL6Q8VoLqfhZnR%2BlM%3D&

You could grep out of the form post the object that created the postbck (__EVENTTARGET), and what its postback value is (DropDownList1=2). You could store the state of the last selected item value in whatever mechanism you choose and do your own compare, even in your custom page_load.

Thanks. I reckon that's probably the way to go.

I was contemplating (but probably wouldn't have actually done) a pretty horrible solution as I was playing with adding my own

__VIEWSTATE

hidden input with the GUID and it almost works if I strip out the extra "," that I get on the form post from the redundant ASP.NET added control of the same name!

I still hadn't sussed out how to change the XML envelope to reflect that change though..


When you say "change the XML envellop to reflect that change" you're talking about changing the XML response from the server that contains all the delta bits for the clientside framework, right (the XML that directs the client code to do its DHTML tricks to update the content within the UpdatePanel)?

So, before we go any further - your problem is that you can now detect when the change is made, but the atlas server code still doesn't and, therefore, doesn't include the right junk in the XML response back to the client to update the doodads in your UpdatePanel control?


Yes that's correct.

BTW: I've had a look at your blog and I suspect you're going to tell me that you know how to do this.

I'm a bit torn on the best way of doing this as.

I reckon__EVENTTARGET is probably the more robust way of doing it even though I lose a lot of the benefits of the ASP.NET module (I need to figure out how to store and retrieve the initial values of controls without using view state and raise the change events myself)

If I try and hijack the __VIEWSTATE control for my own purposes then a lot of the code is written for me already but my solution could break if a new version of ATLAS or update to ASP.NET comes out!


Actually Ben.

I've tried your suggestion and it's trickier than I thought it would be.

The problem is that when I select the original value in the Master ListBox nothing is sent back to the browser!

I assume that this is some sort of optimisation to only send back the things which are different and (as far as ASP.NET knows from looking at the old ViewState) it doesn't have to send anything back as they are the same.

It looks like I am going to need to integrate it with ViewState somehow. For the time being I've commented out my overrides and am sending all ViewState to the Client to get it working.

However I would be extremely grateful for suggestions of ways to get around this issue and get the benefits of both ServerSide ViewState Storage and ATLAS.


...let me dink around a bit with some stuff on my side here and try to duplicate what you're running into more accurately. This has got me curious about several things going on...


Can you visit this page and tell me how accurately this matches your situation:http://www.ben-rush.net/public/testsites/atlaswebsite3/.

I have a textbox and a listbox, the textbox updates its content to the selected index of the listbox when the selectedindex changes. The viewstate for the listbox is off. I don't believe that the listbox requires viewstate for identification of changes because the "change" will only occur when the index is changed; therefore a form post that includes the listbox as an eventtarget will be seen as a selectedindexchanged event. I could be wrong, but I seem to remember this being the case (I did some viewstate optimizations for a shopping cart system a long, long time ago).

Regardless, look at these two fiddler dumps, one during change from index 0 -> 1 (value 1->2), the other from 1->0 (value 2->1). Both show the value of the listbox.

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=2&TextBox1=0&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&

And the other...

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=1&TextBox1=1&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&


I should probably mention that I have a trigger in the UpdatePanel as well.

I suspect that it may be a trigger optimisation causing the issue (for the same reason as previously described it can't realise that there is a change to process so returns an empty envelope)

<Triggers>

<atlas:ControlEventTriggerControlID="drpMasterListBox"EventName="SelectedIndexChanged"/></Triggers>

Well yes that is definitely working.

Do you have a trigger?

Is your UpdatePanel set to the same options as mine or is anything different?

(I haveMode="Conditional"RenderMode="inline")

In any event I'm thinking of doing it without update panels now and using a custom extender.

I was hoping that UpdatePanels would be a quick and dirty solution but I'm not progressing as fast as I wanted to and I suspect I may hit yet more obstacles because my UpdatePanel is in a UserControl which I was planning to embed in another UpdatePanel at Page Level.


No, I don't have a trigger. I changed my rendering modes to what you have, and it didn't change things (I wouldn't expect that it would). You can visit the same page URL I gave you earlier to confirm.

If you have a control in your update panel that does a postback automatically (say, the listbox control with its autopostback option on), then you have no need for a trigger. Triggers will only be useful for controls that don't postback automatically. I haven't researched triggers much, but if they're anything like binding objects then the control they're bound to needs to be AJAX savvy anyway.

Try turning off the trigger, I guess - and see what that does.


MartinSmithh:

The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

well, though i haven't tried it, i think it's safe to assume that your field will allways be maintained if you add it to the page by using the registerhiddenfield of the clientscriptmanager api.

Change datasource for a datagrid using ajax

Hi ppl,

I have a datagrid with XML's as a source file. I have a combo box in the same page and when a user selects a value from the combo box i want to display different stats data without doing a normal postback. I am still learning the updatepanel Ajax control . Can anyone please guide me what i should i do to achieve the functionality? do i need to write any function in js ?

Any help much appreciated

thanks

Place the UpdatePanel around the DataGrid and the Combobox. Make sure the combobox do a postback, set the Autopostback attribute to true. Hook up to the OnSelectedIndexChanged event and get the data based on the selected value and bind it to the DataGrid. When a control inside a UpdatePanel will do a postback, the content of the UpdatePanel will be updated.

If you layout of you page don't allow a UpdatePanel around your combobox, you can instead add a async. postback trigger to the UpdatePanel that will listen to a control's event and update the panel.


Hi Thanks for the response. I placed as the gridview control in the updatepanel and used async trigger as you mentioned. when i changed the dropdownlist the grid doesnt appear at all.

Here is the script and code:

<

divID="Panel1"style="width: 568px; position: static; height: 180px; background-image: url(images/bg-nav.png);">

<spanstyle="color: #ffffff"><strong>

Select L :

</strong></span><asp:DropDownListID="DropDownList1"runat="server"Width="134px"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"><asp:ListItemSelected="True"Value="1">yes</asp:ListItem><asp:ListItemValue="2">no</asp:ListItem></asp:DropDownList><br/><asp:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="test"><ProgressTemplate><divstyle="color: #ffffff; background-color: transparent"><imgsrc="images/indicator.gif"/>

Updating ....

</div></ProgressTemplate></asp:UpdateProgress><asp:UpdatePanelID="test"runat="server"><ContentTemplate><asp:GridViewID="GridView1"runat="server"ForeColor="Silver"BorderColor="LimeGreen"BorderStyle="Inset"AutoGenerateColumns="True"><AlternatingRowStyleBackColor="LightSkyBlue"ForeColor="#404040"/></asp:GridView></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/></Triggers></asp:UpdatePanel>

Code:

ProtectedSub DropDownList1_SelectedIndexChanged1(ByVal senderAsObject,ByVal eAs System.EventArgs)If DropDownList1.SelectedValue = 1ThenDim myDataSetAsNew DataSet()

myDataSet.ReadXml(Server.MapPath(

"test1.xml"))

GridView1.DataSource = myDataSet

GridView1.DataBind()

ElseDim myDataSetAsNew DataSet()

myDataSet.ReadXml(Server.MapPath(

"test2.xml"))

GridView1.DataSource = myDataSet

GridView1.DataBind()

EndIf

EndSub

When i give wrong XML File name, it comes up with the message saying that it cant find the xml file. Is it something i missing in grid control?

Any help much appreciated?


I copied your code, created 2 example XML files, and everything worked fine for me. When I select a value the GirdView was displayed with the correct XML file.

Hi Fredreik

Can you post your sample XML files? I tried using without AJAX functionality and its working fine :(

thanks


I can't think it has anything to do with your XML files, btw do you use the ASP.Net Ajax version 1.0 RTM, becuase your code runs on my machine with no problems at all so I can't see why it shouldn't work on yours.. maybe you have some more code that I don't have.. I only copy the code you posted.. mabye you do something in code-behind etc..!?

Monday, March 26, 2012

Change asp:ListItem Asynchronously

Hi. I′m trying to change the asp:ListItemText value asynchronously from asp:Textbox value.

The html-output from asp:RadioButtonList is somthing like this (simplefied version) :

<table id="x" border="0">
<tr>
<td><input id="x_0" type="radio" name="x" value="Value 0" /><label for="x_0">Text 0</label></td>
<td><input id="x_1" type="radio" name="x" value="Value 1" /><label for="x_1">Text 1</label></td>
<td><input id="x_2" type="radio" name="x" value="Value 2" /><label for="x_2">Text 2</label></td>
</tr>
</table>

As you can see, there is no id for the following "label".

I can change the input value: $get("x_0").value = "something";

But how can I change the following label .innerHtml. That is f.x. the "Text 0" string ?

I believe the following should work:

$get("x_0").innerHTML = "something";

------------------
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


Thanks, but that is not the solution, because the input is closed before the label starts.

If this was the case... :
<input id="x_0" type="radio" name="x" value="Value 0"><label for="x_0">Text 0</label></input>

...in stead of how it is:
<input id="x_0" type="radio" name="x" value="Value 0" /><label for="x_0">Text 0</label>

Then I would not have a problem.


Since there is no ID for the label, you have to loop through the labels of the list to find the one that matches the radio button id you are looking for

var container = document.getElementByID("x");

var labels = container.getElementsByTagName("LABEL");

for(var x = 0; x < labels.length; x++)
{
if(labels[x].htmlFor == "x_0")
labels[x].innerText = "changed 0";
}


Thank you DMAR78. This works great.Party!!!

CascadingDropDownProperties - Creating an extra Category/Value through code

I need to add an initial "filter" to my CascadingDropDown Lists.

How do I create a Property, and assign a value and category to it through code?

Thank you,

Bryan

I'm afraid I don't understand - could you please rephrase the question?

Saturday, March 24, 2012

CascadingDropDownExtender - preselected value

I used the dropdown extender a lot and noticed now a strange behavior, that makes it kind of a showstopper, if there is no workaround:

I have three DropDownLists exactly like in the example of the Toolkit. Except for the first DropDownList all values are filled in via the DropDownExtender. I did not use the optional PromptText property, because I do want to have the first value in each DropDownList preselected. This looks OK, so if I change the value of the first DropDownExtender, the values update in a cascade and the first item of each dropdown seems to be preselected - perfect. But if a postback happens now, the actual DropDownLists are empty and no value is selected, they are only selected, if the user would go on and open the drop down list and really select a value only then the values are also visible on the server side.

Is there any method I could call on the extender or on the dropdownlist to make the values visible on the server after a postback without having the user to click on the combobox and select the same value he already sees? That would be kind of hard to explain...

The behavior is easily to reproduce with the example from the Toolkit, just change in CascadingDropDown.aspx

 <table> <tr> <td>Make</td> <td><asp:DropDownList ID="DropDownList1" runat="server" Width="170" /></td> </tr> <tr> <td>Model</td> <td><asp:DropDownList ID="DropDownList2" runat="server" Width="170" /></td> </tr> <tr> <td>Color</td> <td><asp:DropDownList ID="DropDownList3" runat="server" Width="170" AutoPostBack="true" /></td> </tr> </table> <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="DropDownList3_SelectedIndexChanged" /> <br /> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1" Category="Make" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents" /> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2" Category="Model" ServiceMethod="GetDropDownContentsPageMethod" ParentControlID="DropDownList1" /> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3" Category="Color" ServicePath="~/CascadingDropDown/CarsService.asmx" ServiceMethod="GetDropDownContents" ParentControlID="DropDownList2" />

ups... always learning... there is a "isDefault" flag on the CascadingDropDownValue collection, that just has to be set... problem solved!

CascadingDropDown: Pulling selected values from a cookie

I am using the CascadingDropDown extender from the AjaxControlToolkit and I was wondering if there was an easy way to set the selected value and to populate child drop downs when the page loads. I am storing a users previous selections in a cookie so when they start a new form these values are already selected. I did some looking at the CascadingDropDown code but I didn't see an easy way to accomplish this. Does anyone know an easy way to do it?

Or am I going to have to cobble some JS together to make it happen?

Thanks.

Derek

Couldn't you just do something like

myCascadingDropdownListExtender.SelectedValue = Request.Cookies("MyCookie")

on Page_Load ? It works for me.

CascadingDropDown with two items containing the same value

I'd like to create a cascading drop down control with two list items that have the same value and also be able to programmatically populate the drop down via the selected item's text. I haven't seen anything like this and I can't see a way to do it.

In the sample pages I've changed the CarService.xml file as follows:

1 <make name="Audi" value="Audi (value)">2 <model name="A4" value="A4 (value)">3 <color name="Azure" value="Azure (value)" />4 <color name="Light Azure" value="Light Azure (value)" />5 <color name="Dark Azure" value="Dark Azure (value)" />6 <color name="Test Azure" value="Dark Azure (value)" />7 </model>

...adding the "Test Azure" color node with the same value as "Dark Azure". Note that when you select "Dark Azure" on the page, then select "Test Azure", theDropDownList3_SelectedIndexChanged event doesn't fire.

Does anyone know how to do this?

Hi,

I tried it, it worked fine.

I add the line

<color name="Test Azure" value="Dark Azure (value)" /> to the xml file as you described, and didn't modify a line of code.
 

I tried it again and still no dice. It may not be possible:

I created the following page to test regular asp.net...

<%@. 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 ddlTest_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = String.Format("{0} - {1}", ddlTest.SelectedIndex, ddlTest.SelectedValue); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged"> <asp:ListItem Text="Apple" Value="Red"></asp:ListItem> <asp:ListItem Text="Banana" Value="Yellow"></asp:ListItem> <asp:ListItem Text="Apple Again" Value="Red"></asp:ListItem> </asp:DropDownList> <asp:Label ID="Label1" runat="server"></asp:Label> </div> </form></body></html>

Notice that selecting "Apple Again" will autopostback with "Apple" selected. I'll look for another solution.


That's because "apple" and "apple again" have the same value.

CascadingDropDown With more then one parameter?

I am trying to use the CascadingDropDown drop down extender in a DataView.

I have three drop-downs where ddl1 contains the main lookup value. When I select ddl1, the second dropdown ddl2 populates perfectly. The problem that I have however is that the 3rd drop down is dependent on both the selected value in ddl1 and another value/column in the row. Does anyone know whether this is achievable with the CascadinDropDown extender at all? I guess i need a way to make the web service have more parameters and a way to pass the parameters to the webservice.

Any help would be highly appreciated!!

Does anyone know how I can get the Cascading DropDowns to have more then one parent id. I really need to figure out how to make the third drop down populate based on the value selected in the 1st drop down and another value from the grid... this must be acheivable.. I can't be the only one trying to do this...


Sorry, this scenario is not currently supproted by CDD.

CascadingDropDown set value

Hi,
I am new to ASP.NET and I have a question regarding the CascadingDropDown Ajax control. Can you set the dropdown list to one of the values instead of "please select etc"?
Thanks.

You should be able to set the LoadingText and the PromptText properties of the CascadingDropDown control to say anything you want.

Regards,

Scott Lance
Application Developer
Children's Miracle Network

CascadingDropDown SelectedValue

Is there a way to set this to a variable such as a Session variable, or must this value be known at compile time? Thanks!

Michael LaneI found the answer indirectly in the FAQ. This works:

CascadingDropDown1.TargetProperties[0].SelectedValue = "1";