Showing posts with label drop. Show all posts
Showing posts with label drop. Show all posts

Wednesday, March 28, 2012

PostBack Problem, Need Help.

I have a page with a drop down that drives a gridview. Now whatever is selected the drop down will drive whats shown in the gridview. The page loads fine and the default value in the drop down loads the gridview fine. Now on each row in the gridview I have an edit button to edit that row. I use a modal popup to edit that row and save it. The modal works great and updates a row. Here is where the problem happens, if I change the drop down to a different value the gridview updates, I edit the row and the modal pop is ok and saves...but without changing the drop down again if I try to edit another row I get this error...

--------
Windows Internet Explorer
--------
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@dotnet.itags.org. Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
--------
OK
--------

Now I have tried adding that attrbute to the page tag and it still does not work...it gives me a similar error than the above one. I assume it has something to do with having all these postbacks and the modal is causing one while so is the edit button and they are conflicting somehow...anyway, any direction or solution would great. Let me know if anyone needs to see some code.

Hi Horizon,

In your modal popup, do you make partial or full postback when you update the datagrid row?

If you make partial postback, there is chance the server does not know all about this partial update, especially if you modify or update portions of your page, so by the next time you try to issue partial postback the server will complain about invalid postback event arguments.

It works if you change the dropdown because the dropdown issues full postback so the server now knows about all modifications on your page.

Is it an option to issue a full postback when you update the rows in the datagrid?

If your application does not require high grades of security, you could turn off the enableEventValidation attribute globally for your application (in web.config file).

Probably some ASPX and code-behind code would be helpful here to see how exactly you do the postbacks and updates on your page...

Kind regards,

sbogus.


Thanks you lead me on the right path, I added this to the load event...

ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);

What this does is cause a full post back on the page now when I click btnSaveRankings which is in my modal panel. Though know its not saving state on my drop down...it reverts it back to the value as if you just came into the site...I am going to post my aspx and aspx.cs file...

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="PowerRankingsAjax.admin.index" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit" %><!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>Add/Edit Power Rankings</title> <link href="../ModalDialogs.css" rel="stylesheet" type="text/css" /></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="lblError" runat="server" Text=""></asp:Label> <ajaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxControlToolkit:ToolkitScriptManager> Edit Past Issues <br /> Select Issue: <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlIssue_SelectedIndexChanged"></asp:DropDownList> <br /> <asp:UpdatePanel ID="uEditPanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="EditPowerRankings" runat="server" AutoGenerateColumns="false" OnRowCreated="EditPowerRankings_OnRowCreated" > <Columns><asp:TemplateField ShowHeader="False"><ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" CausesValidation="false" /></ItemTemplate></asp:TemplateField><asp:BoundField DataField="pid" /><asp:BoundField DataField="teamabbr" /><asp:BoundField DataField="team" HeaderText="Team" SortExpression="team" /><asp:BoundField DataField="rank" HeaderText="Rank" SortExpression="rank" /><asp:BoundField DataField="comment" HeaderText="Comment" SortExpression="comment" /></Columns> </asp:GridView><!--cheesy button for the modal popups target control--> <asp:Button ID="btnHiddenRankings" runat="server" style="display: none" /> <ajaxControlToolkit:ModalPopupExtender ID="mpeRankings" runat="server" TargetControlID="btnHiddenRankings" PopupControlID="pnlRankings" CancelControlID="btnCancelRankings" BackgroundCssClass="modalBackground" Drag="true" > </ajaxControlToolkit:ModalPopupExtender> <asp:Panel ID="pnlRankings" runat="server" CssClass="modalBox" Style="display: none;" Width="500px"><asp:Panel ID="RankingsCaption" runat="server" CssClass="caption" Style="margin-bottom: 10px;">Edit Rankings</asp:Panel> <asp:HiddenField ID="hidRankEditIndex" runat="server" Value="-1" /><div class="divCol"></div><div class="divColLast"> <asp:Image ID="imgTeam" runat="server" />  <asp:Label ID="lblTeamName" runat="server" Text=""></asp:Label></div><div class="clearer"></div><div class="divCol">Rank:</div><div class="divColLast">   <asp:DropDownList ID="ddlEditRank" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> <asp:ListItem>7</asp:ListItem> <asp:ListItem>8</asp:ListItem> <asp:ListItem>9</asp:ListItem> <asp:ListItem>10</asp:ListItem> <asp:ListItem>11</asp:ListItem> <asp:ListItem>12</asp:ListItem> <asp:ListItem>13</asp:ListItem> <asp:ListItem>14</asp:ListItem> <asp:ListItem>15</asp:ListItem> <asp:ListItem>16</asp:ListItem> <asp:ListItem>17</asp:ListItem> <asp:ListItem>18</asp:ListItem> <asp:ListItem>19</asp:ListItem> <asp:ListItem>20</asp:ListItem> <asp:ListItem>21</asp:ListItem> <asp:ListItem>22</asp:ListItem> <asp:ListItem>23</asp:ListItem> <asp:ListItem>24</asp:ListItem> <asp:ListItem>25</asp:ListItem> <asp:ListItem>26</asp:ListItem> <asp:ListItem>27</asp:ListItem> <asp:ListItem>28</asp:ListItem> <asp:ListItem>29</asp:ListItem> <asp:ListItem>30</asp:ListItem> </asp:DropDownList></div><div class="clearer"></div><div class="divCol">Comments:</div><div class="divColLast"> <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine" MaxLength="500" Width="480" Height="200"></asp:TextBox></div><div class="clearer"></div><div style="white-space: nowrap; text-align: center;"> <asp:Button ID="btnSaveRankings" runat="server" Text="Save" OnClick="btnSaveRankings_Click" CausesValidation="true" /> <asp:Button ID="btnCancelRankings" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancelRankings_Click" /></div></asp:Panel> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlIssue" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form></body></html>

cs file...

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;namespace PowerRankingsAjax.admin{public partialclass index : System.Web.UI.Page { powerrankings oPowerrankings =new powerrankings(); DataSet ds =new DataSet();public String strWeek;public int intCountVal;protected void Page_Load(object sender, EventArgs e) { ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);if (oPowerrankings.ConnectToDatabase(lblError) ==true) {if (!Page.IsPostBack) {//GetWeek GetWeek(); BuildEditList(); BuildEditGrid(strWeek); } } ds.Dispose(); }protected void GetWeek() {//Current Week strWeek = oPowerrankings.GetMaxWeek(ds, lblError); }protected void BuildEditList() { ddlIssue.DataSource = ds.Tables[oPowerrankings.GetAllWeeks(ds, lblError).ToString()]; ddlIssue.DataTextField ="week"; ddlIssue.DataValueField ="week"; ddlIssue.DataBind(); intCountVal = oPowerrankings.GetHolder(ds, lblError);if(intCountVal > 0) { ListItem li =new ListItem("Edit","edit"); ddlIssue.Items.Add(li); }else { ListItem li =new ListItem("New","new"); ddlIssue.Items.Add(li); } lblError.Text = intCountVal.ToString();//ddlIssue.SelectedValue = strWeek; }protected void BuildEditGrid(string strWeek) { EditPowerRankings.DataSource = ds.Tables[oPowerrankings.GetEditPowerRankings(strWeek, ds, lblError).ToString()]; EditPowerRankings.DataBind(); }protected void ddlIssue_SelectedIndexChanged(object sender, EventArgs e) { strWeek = ddlIssue.SelectedValue;if (oPowerrankings.isNumeric(strWeek, System.Globalization.NumberStyles.Integer)) { BuildEditGrid(strWeek); }else { } }protected void EditPowerRankings_OnRowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[1].Visible =false; e.Row.Cells[2].Visible =false; }protected void btnSaveRankings_Click(object sender, EventArgs e) { oPowerrankings.UpdatePowerRankings(Convert.ToInt16(hidRankEditIndex.Value), Convert.ToInt16(ddlEditRank.SelectedValue), txtComment.Text, lblError); mpeRankings.Hide(); strWeek = ddlIssue.SelectedValue; BuildEditList(); BuildEditGrid(strWeek); uEditPanel.Update(); }protected void btnCancelRankings_Click(object sender, EventArgs e) { mpeRankings.Hide(); }protected void btnEdit_Click(object sender, EventArgs e) { Button btnEdit = senderas Button; GridViewRow row = (GridViewRow)btnEdit.NamingContainer; hidRankEditIndex.Value = row.Cells[1].Text; imgTeam.ImageUrl ="../images/" + row.Cells[2].Text +".gif"; lblTeamName.Text = row.Cells[3].Text; ddlEditRank.SelectedValue = row.Cells[4].Text; txtComment.Text = row.Cells[5].Text; uEditPanel.Update(); mpeRankings.Show(); } }}

Povide Drag Option across Datagrids(Drag and Drop)

Thanks in advance for assisting me,

I am developing a asp.net web application(VB.Net).

I am New to AJAX and have a requirement where i should be able to select(say using a check box) and drag(move) a particular or a set of rows from one datagrid to a another datagrid in the same page.

Is this feasible ,what should be the approach......

Hi,

If your using checkbox or any other way to mark the rows you wanted move..... you can either create a xml ....(The data to be moved) or you can create a temp table and you can update the new datagrid... well, I am not quite sure that, through client side code the data can be moved between two datagrid is possible..? May be primary datagrid data can be as XML document though which the secondary data grid can be updated......

Monday, March 26, 2012

Preview DragDropManager does not work at all

I'm writting an application that uses extensively drag and drop. It used Sys.UI.DragDropManager and worked fine on July CTP. Now I'm getting a lot of errors in the new Preview DragDopManager. I guess I should not using this one, instead I'm trying to use AjaxControlToolkit.DragDropManager, as it seems to work with the Ajax Control Toolkit.

Hi,

you're right, the DragDropManager defined in the CTP uses type methods (Array.add, Array.remove) that aren't defined anywhere. The DragDropManager contained in the AjaxControlToolkit is the one contained in the July CTP, though you might want to correct the following issue until a Toolkit refresh is available:

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


Thank you Garbin. I'm using AjaxControlToolkit.DragDropManager with the suggested workaround and it seems to work properly. However there is another bug in the DragDropManager. In some circumstances (sorry I can tell you exactly what circumstances), DragDropManager calculates incorrectly the statingPoint. This bug was in July CTP and is in AjaxControlToolkit.DragDropManager. Sometimes, when you start dragging a control, the drag visual goes way from its natural position, it goes below and right. I'm using the following workaround IDragSource behavior:

// cuando se pulsa con el ratón en el asa para mover
// se comienza la operación Drag and Drop
function OnMoveHandleMouseDown(e)
{
//debug.trace('OnMoveHandleMouseDown');

_startingMove = true;

// salvamos la posición actual del ratón
// para poder calcular luego startingPoint.
_lastClientX = e.clientX;
_lastClientY = e.clientY;

// salvamos la posición del control
// y del scroll para poder calcular luego startingPoint
var x = parseInt(_frame.style.left.replace('px',''));
var y = parseInt(_frame.style.top.replace('px', ''));
var scroll = Sys.UI.Control.getScrollPosition( _frame );

saveOriginalPosition();
window._event = e;
AjaxControlToolkit.DragDropManager.startDragDrop(this, _frame, null);

//hay un bug en el DragDropManager que calcula incorrectamente
//startingPoint, con lo que el control se va lejos
//de la posición donde debería estar. Por eso hay que reponer
//la posición de control y calcular el startingPoint
resetPosition();
_frame.startingPoint = {
x: _lastClientX - x + scroll.x,
y: _lastClientY - y + scroll.y
};

if (window.__safari) {
document.onselectstart = _onSelectStartDelegate;
} else {
$addHandler(document, 'selectstart', _onSelectStartDelegate);
}
}

Basically I'm calculating the startingPoint, I'm assuming (i konow it) that _frame.style.position = 'absolute'.

Here is saveOriginalPosition:

function saveOriginalPosition()
{
var left = parseInt( _frame.style.left.replace('px', '') );
var top = parseInt( _frame.style.top.replace('px', ''));
_originalPosition = { x:left, y:top };
}

and Sys.UI.Control.getScrollPosition:

Sys.UI.Control.getScrollPosition = function(element) {
var scrollLeft = 0;
var scrollTop = 0;
var parent;

for (parent = element.parentNode; parent; parent = parent.parentNode)
{
if (parent.scrollLeft) {
scrollLeft += parent.scrollLeft;
}
if (parent.scrollTop) {
scrollTop += parent.scrollTop;
}
}
return { x: scrollLeft, y: scrollTop };
}


I mean I can't tell you ...

Hi,

thank you for posting the code, I'll try to understand what's happening there.

Let me know if you manage to write a repro for this issue.


Sorry, but time restrictions prevent me to create a simple repro. However I can tell you what I discovered.

1) the _drag method sets the location (setLocation(position)) based on this calculus:

position = mousePosition - statingPoint + scroll // please, assume these are 2D vectors and we have overloaded the operators.

2) when starting the dragging operation, if the original position of drag visual is 'absolute', the position must not be changed and:

staringPoint must be = mousePosition - position + scroll

3) However startDragDrop method calculates starting point as:

startingPoint = mousePosition - getLocation + scroll

getLocation can be different (likely greatter) than position (style.left , style.top) for an absolutely postioned element if it has a positioned ancestor other than body. This is because the drag visual moves down and right when starting the drag operation

4) startDragDrop contains an extrange logic. It does:

dragVisual.style.position = "absolute";

....

if (dragVisual.style.position == "absolute") {
dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, Sys.UI.DomElement.getLocation(dragVisual));
}
else {
var left = parseInt(dragVisual.style.left);
var top = parseInt(dragVisual.style.top);
if (isNaN(left)) left = "0";
if (isNaN(top)) top = "0";

dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, { x: left, y: top });
}

comparing position == 'absolute' has no sense if you previously set position = 'absolute'

I also think (not sure) it should be:

if (dragVisual.style.position != "absolute") {
dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, Sys.UI.DomElement.getLocation(dragVisual));
}
else {
var left = parseInt(dragVisual.style.left);
var top = parseInt(dragVisual.style.top);
if (isNaN(left)) left = "0";
if (isNaN(top)) top = "0";

dragVisual.startingPoint = this.subtractPoints(dragVisual.startingPoint, { x: left, y: top });
}

...

dragVisual.style.position = "absolute";


Ok, here is a repro:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@. 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">

<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= "sm" runat="server">
</asp:ScriptManager>
<h1>Bug demostration</h1>
<p /><p /><p /><p /><p />
<div style='position:relative'>
<asp:Panel runat="server" ID="panel1" style='position:absolute;left:50px;top:50px;width:50px;height:100px;background-color:Blue;'>
<asp:Panel runat="server" ID="handle" style='position:absolute;left:0px;top:0px;width:50px;height:20px;background-color:Green;'>
</asp:Panel>
</asp:Panel>
<ajaxToolkit:DragPanelExtender ID="DragPanelExtender1" runat="server"
TargetControlID="panel1" DragHandleID="handle" />
</div>
</form>
</body>
</html>

Please, try to drag the panel, you will see how the drag visual moves down and right when you start the drag operation.

I applied the above changes and it seems to work :-)


Hi,

thanks. Is the above repro using the modified version of the Toolkit (i.e. the one with the fix suggested in the first reply) ?


Yes,
Whithout any changes, the repro shows the bug, with your first fix, the repro still shows the bug. With the fix I suggested does not show the bug.

Hi,

where is the file stored that has to be changed?


Jesús:

Whithout any changes, the repro shows the bug, with your first fix, the repro still shows the bug. With the fix I suggested does not show the bug.

Months later this bug still exists in the March '07 release. Any idea from MSFT if this fix will be incorporated into a release?

Gerry


Jesús:

Whithout any changes, the repro shows the bug, with your first fix, the repro still shows the bug. With the fix I suggested does not show the bug.

Months later this bug still exists in the March '07 release. Any idea from MSFT if this fix will be incorporated into a release?

Gerry


Jesús:

Whithout any changes, the repro shows the bug, with your first fix, the repro still shows the bug. With the fix I suggested does not show the bug.

Months later this bug still exists in the March '07 release. Any idea from MSFT if this fix will be incorporated into a release?

Gerry


Where do you incorporate this fix? You can show this in the case of your example.

Thanks

Vid

Saturday, March 24, 2012

Problem in Cascading Drop Down

I have created a website using Cascading DropDown in AJAX control tool kit......

I have 3 DropDown lists.....and the list in 2nd one is populated when an Item from 1st DropDown List is selected...Similarly 3rd DropDown is populated depending on 2nd list.....

My problem is that I get all my values in dropdown 3 list but I wanted to show the whole list of items in my result.....means suppose at the end of the selection I have 3 items in DropDown list 3 then all the items in tat list shud be my result......

can u tell me how to extract tat all the items from DropDown list 3 and display it.....

Hi Hemil,

Based on my understanding, there are three DropDownlists in the page. The second DropDownList is bound according the item selected in the first DropDownList. The third DropDownList is bound according the item selected in the second DropDownList. Now you want to know how to get all the items of third DropDownList. In one word, you want to know how to get a DropDownList's items. If I have misunderstood you, please feel free to let me know.

To get all the items of DropDownList, you should use loop to get them.

To better understand your question, could you please confirm the following information:

If you want to get the value of item, the code should like as follows:

string strResult ="";foreach (ListItem itemin DropDownList1.Items) { strResult += item.Value; } 


Ya u got my problem rite but only thing is that I have all the items in Drop Down list 3 which is populated according to the Items selected from Drop Down1 and Drop Down2.....

So after selecting items from DropDown 1 and 2 I get my result in Drop down 3 Which I need to display all at once.....means all items in drop Down list 3.....

So watever code U gave me will work or no and if yes will it work if i change the item in Drop Down 1 or 2 accordingly Dropdown 3 will change so will it append to the Display result.......I have used Cascading Dropdown of AJAX Control tool kit......

<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
ServiceMethod="GetDropDownContents"
UseContextKey="True"
Category="major"
LoadingText="[Loading majors...]"
PromptText="Degree Major/ Program Name"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList1">
</ajaxToolkit:CascadingDropDown>

<br /><br />

<asp:DropDownList ID="DropDownList2" runat="server"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server"
ParentControlID="DropDownList1"
Category="type"
ContextKey="[Loading major types...]"
PromptText="Degree Major/ Program Type"
ServiceMethod="GetDropDownContents"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList2">
</ajaxToolkit:CascadingDropDown
<br /><br /
<asp:DropDownList ID="DropDownList3" runat="server"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" Visible="true">
</asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server"
ParentControlID="DropDownList2"
Category="campus"
ContextKey="[Loading campus names...]"
PromptText="Campus"
ServiceMethod="GetDropDownContents"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList3">
</ajaxToolkit:CascadingDropDown>


Hi Hemil,

The code I posted above is only a simple example, which tells you how to loop the DropDownList. You can use different way to display the result according your requirements.

I hope this helps.


Sir,

I tried implementing ur code but I get only the value which is selected item in Drop Down instead of all the values in DropDown List 3......

I will tell you something more on this...I want to display the result after I select Item in Drop Down List 2.......means as soon as I select one item from Drop Down List 2 and then I should press Submit button so It should give me all the values contained in Drop Down list 3 which I will make Invisible to the user.....So in short there is dropDown list behind the scenes which has all the values in DropDown list........I want to display all the Items in dropdown list 3........after I press Submit button......

So the sequence of operations will be.....

1. Select one item from DropDownlist 1

2. As per the selection in dropdown list 1, Drop Downlist 2 will be populated with values so Select item from drop down List 2.

3. Now behind the scenes I have drop down list 3 but I dunt want to show the DropDown....it has all the Items which I need to display to the user...

4. There is one Submit button which I have to press and it should show all the Items from Drop DOwn list 3...which is present behind the scenes...

Thanks,

hemil.



Hi Hemil,

Thanks for your response.

Based on my understanding about your response above, you should bind the DropDownList3 and then loop this DropDownList3 to display Values in the Button event.

The code of Button event should like as follows:

protected void Button1_Click(object sender, EventArgs e) {//Bind DropDownList3 by the item selected in the DropDownList2 DropDownList3.DataSource = YourDataSource; DropDownList3.DataTextField ="DisplayField"; DropDownList3.DataValueField ="ValueField"; DropDownList3.DataBind();string strResult ="";//loop DropDownList3foreach (ListItem itemin DropDownList3.Items) { strResult += item.Value; } }


I hope this helps.


Hi Hemil,

If you have any question, please post them here and don't need to email me directly. We are glad to help you. If you post the question here, other kindly people will help you too. Thanks for your understanding.

Based on your question and the codes you sent to me, you cannot bind the XML file to DropDownList directly. You should read the XML file to a DataSet or XmlDataSource and bind the DropDownList with the data source.

The code should like as follows:

<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml"></asp:XmlDataSource>

</div>
</form>

protected void Button1_Click(object sender, EventArgs e) { XmlDataSource1.XPath ="/MajorsDatabase/major/type";// Use xpath to filter data you want to display. DropDownList3.DataSource = XmlDataSource1; DropDownList3.DataTextField ="name"; DropDownList3.DataValueField ="name"; DropDownList3.DataBind(); }

I hope this helps.


The code is working ... Thanks ...

But I am facing a new problem ... which is ,.... when I select the first and second drop down box .. I get all the names of the campuses ... where as ... it should display me only campus names depending on the DDL1 and DDL2 selection ...

i.e. DDL => DropDownList

When I select from DDL1 - "Acturial Science"

and DDL2 - "b" ... it should give me only ... Campus Name as "San Jose" and "San Diego".

but it is giving all the Campus name from the XML file under the tag "campus" ...

Is there any way we can query the DataBinding or DataSource ...

Thanks.....


Hi Hemil,

You should add XPath to filter the data you want to display.

For example, If you want to get the type names, which are the child node of major node and this major node's name property is "Advertising", the XPath should like as follow:
XmlDataSource1.XPath = "/MajorsDatabase/major[@.name='Advertising']/type";

So you can write the XPath to filter the data. For more information, seeXmlDataSource.XPath Property.


I hope this helps.


Good Afternoon,

Thanks a lot for the guidance... the code works just perfect for the Static values.

I would like to ask you few things like ...

1. can we pass dynamically selected arguments in Xpath ?

2. do we need to write a query for this dynamic invocation ?

I was trying ...

XmlDataSource1.XPath ="/MajorsDatabase/major [DropDownList1.SelectedItem.Text] /type[DropDownList2.SelectedItem.Text]/campus";

But is is not working ...

As we are selecting Major from DDL1 and Type from DDL2 ... I would like to pass those dynamically selected values in XPath ....

I was also trying ...

int one = 1, two = 1;

XmlDataSource1.XPath ="/MajorsDatabase/major[one] /type[two]/campus"; ====> Not working ... where as if we write

XmlDataSource1.XPath ="/MajorsDatabase/major[1] /type[1]/campus"; ====> works ...

Thanks Again ...


Hi Hemil,

Yes, we can pass parameters to XPath dynamically and easy. Since the parameters are variables, we cannot write them in the XPtah string directly. We should use plus to connect the XPath and parameters.

For example:

string strParameter ="Advertising"; XmlDataSource1.XPath ="/MajorsDatabase/major[@.name='"+strParameter+"']/type";


I hope this helps.


Thanks very much for all your help.

Code is working fine.

Wednesday, March 21, 2012

Problem in Script Manger ?

Hi , I use AJAX my project but I have a problem … When I drag and drop the ScripManger in my page , this error will be occur : Element 'ScriptManager' is not a known element. This can occur if there is a compilation error in the Web site. Although I don't have any other errors in my website .. What is a problem ?? Please help me …

You must copy the file named "System.Web.Extensions.dll" to the folder named "bin" in your project.

The default path of the file is "C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v.1.0.61025\".

----If the answer helped you please click the "As answer" button----


Hi ,

Thanks for your reply ..

I found the "System.Web.Extensions.dll" as you describeBut I don't have folder named "bin" in my website folder !!

Is there in any folder else ?? or can I found this folder in another place ??

Thaaaaaaaanks..


You could add a folder named "Bin".

Or add reference in the webside then you can see the folder.


I do that – add new Bin file- and but file in it .. but it still the same error !!Note : when I use update panel it also appear the same error but it work ( I means flicker don't appear ) What is the problem ?


also I note that this error occure when the page is from master .. but if it defult page and don't inherint from mster then this error will be appear ..

Please help me ...


Please add the following entry in your web.config:

<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>


Raymond Wen - MSFT:

Please add the following entry in your web.config:

<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>

This entry is already exist in my web config .. but the problem is still appear !!

Plz what can I do ??


Please remove ajax from your system and again install it in your system

problem migrate from atlas to ajax

Hi,

I have the folloving problem.

I' ve downloaded sample drag and drop apllication from codeproject.com (http://www.codeproject.com/Ajax/AtlasDragNDrop.asp) and I need to migrate it from atlas to new ajax v1.0beta.

Problem is I didn't find many sample apllictacion in new Ajax and i have problem to rewrite javascript code:

for example:

orginal:

function addFloatingBehavior(ctrl){
var floatingBehavior = new Custom.UI.FloatingBehavior();
floatingBehavior.set_handle(ctrl);
var dragItem = new Sys.UI.Control(ctrl);
dragItem.get_behaviors().add(floatingBehavior);
floatingBehavior.initialize();
}

my try:

function addFloatingBehavior(ctrl){
var floatingBehavior = $create(AjaxControlToolkit.FloatingBehavior,{'handle' : ctrl}, ctrl );
floatingBehavior.initialize();

}

it doesnt work

next scriptmanager in atlas has something like
<atlas:ScriptReference ScriptName="AtlasUIDragDrop" />

in ajax i cann't find replacement

In simple, my problem is add a floatingbehavior to DIV

(DragPanelExtender is not a solution for me)

Thanx for help

Any suggestion?

Please can anybody help me to write simple page with one button. If i click this button - new element (div) is added to page, and this div have to have floatingbehaior.

If I click button again, next div is created and so on...

It have to be in ajax v1.0 beta ...

If you want to see the same apllication in atlas please look at :http://www.codeproject.com/Ajax/AtlasDragNDrop.asp

It′s very urgent. Please help

Thanks Mayo.


I don't have a full answer, but I can tell you the drag and drop I believe is now in the CTP PreviewDragDrop.js file. with the floating behavior being Sys.Preview.UI.FloatingBehavior.