Showing posts with label runat. Show all posts
Showing posts with label runat. Show all posts

Saturday, March 24, 2012

DropDownLists OnSelectedIndexChanged wont fire

Here what I do

<atlas:UpdatePanel ID="mypanel" mode="always" runat="server">
<ContentTemplate>
<asp:DropDownList ID="mylist" runat="server"
DataSource="mydatasource"
DataTextField="mytext"
DataValueField="myvalue"
OnSelectedIndexChanged="mylist_SelectedIndexChanged" />
<asp:Label ID="mylabel" runat="server" />
<asp:TextBox ID="mytextbox" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger controlID="mylist"
event="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel>

the logic is simple, when the selected item inside the DropDownList changed, it will change the value of the textbox. inside mylist_SelectedIndexChanged method in the codebehind file is just simple putting a value using mytextbox.Text = "something";

But unfortunatelly, when I click on the DropDownList, change it's selected item, nothing happend. The value of the textbox also didn't change.

Do I do something wrong here? or miss something? Please advise.


Thanks,

Lok

As far as I can see all you need to do is set theAutoPostBack="true"in the DropDownList. Works just fine for me that way.

Greetz,
Zentral


Hi Zentral,

Thanks for the reply.

But, it's true, that giving AutoPostBack="true" will not makes all the page portion refreshed? not just only the UpdatePanel portion?

Or because of the control inside an UpdatePanel, so all the postback action happened only affected particular UpdatePanel.

Regards,

Lok


Hey Lok,

That's correct, due to the fact that the DropDownList is nested within an UpdatePanel, only the data within the panel will be considered for the postback. In this case you can look at the UpdatePanel as a "page scope limiter". Thus only the content within the UpdatePanel will be re-rendered.

You can test this easily for example by placing a label inside the UpdatePanel and placing a different label outside the UpdatePanel. Place your DropDownList inside the UpdatePanel and set the AutoPostBack="true", implement the server event and within that event set both labels (the one inside the updatepanel and the one outside) to the same value. You will notice that only the label inside the UpdatePanel will have its value updated while the one outside will remain unchanged.

Greetz!
Zentral

DropDownList SelectedIndexChanged not fire (Autopostback - true!)

1<asp:DropDownList ID="SectionsDDL" runat="server" DataSourceID="SectionsObDS"2AutoPostBack="True" OnSelectedIndexChanged="SectionsDDL_SelectedIndexChanged"3DataTextField="titleName" DataValueField="id">4</asp:DropDownList>56<asp:UpdatePanel ID="UpdatePanel1" runat="server">7<ContentTemplate>8<asp:Panel ID="sectData" runat="server">9<asp:Label ID="tstlbl" runat="server" />10</asp:Panel>11</ContentTemplate>12<Triggers>13<asp:AsyncPostBackTrigger ControlID="sectionsDDL" EventName="SelectedIndexChanged" />14</Triggers>15</asp:UpdatePanel>

Everything is ok when I choose any item in DDL but first. When I choose first SelectedIndexChanged not fire.

I tried to find answer on forum and could not.

it sounds like your first item is selected when the dropdown loads so if you pick that answer the selected index never changes. Try adding an additional item called Not Selected or choos one or something along those lines as the first item in the list then everytime you should postback.

AjaxButter


Or you could change the SelectedIndex property to -1

Wednesday, March 21, 2012

DropDownList dont work inside ReorderList InsertItemTemplate ?

In want to have a DropDownList inside the InsertItemTemplate of my ReorderList.

Like this:
<asp:DropDownList ID="NewRecipientsList" runat="server" Width="180px"
DataSourceID="NewRecipientsSrc" DataTextField="UserName" DataValueField="UserId"
SelectedValue='<%# Bind("UserId") %>' /
But I get this error message at runtime:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

Which I don't understand. Using a TextBox instead works perfectly:
<asp:TextBox ID="Test" runat="server" Text='<%# Bind("UserId") %>' /
And using the dropdownlist in other controls, like FormView or DetailsView does work. I can't understand why the combination of ReorderList + DropDownList doesn't work.Are you sure that's causing the problem? I just tried this with the ReorderList sample page and it worked fine - both in the EditTemplate and InsertTemplate.
No, I'm not sure.
As I said, I don't understand why this doesn't work. But I've noticed that replacing the DropDownList with a TextBox works.

May it be that the error message is misleading ? The "UserId" I'm binding to is a SqlServer uniqueidentifier, could that be a problem ? (Although I think I tried to bind to UserName, which is a string, and it didn't work either)
Are you sure it's not the binding of the DropDownList itself that's having problems? Meaning I notice that it's also databound to another data source.
Yes, I'm sure of that.
If I simply remove theSelectedValue='<%# Bind("UserId") %>' attribute, the problem goes away (and the dropdown is correctly filled).

I would like to know what I am doing wrong, too. I am getting the same error. Here is the code for my page:

<h3>

Sort and Add new Categories</h3>

Select Parent Category to Sort:<br/>

<asp:DropDownListID="DropDownList1"runat="server"AppendDataBoundItems="True"AutoPostBack="True"

DataSourceID="CatListDataSource"DataTextField="CategoryName"DataValueField="CategoryID">

<asp:ListItemValue="-1"><Select Parent Category></asp:ListItem>

<asp:ListItemValue="0">Top Level</asp:ListItem>

</asp:DropDownList><br/>

<br/>

<asp:ObjectDataSourceID="CatListDataSource"runat="server"DeleteMethod="Deletecategory"

InsertMethod="AddCategory"OldValuesParameterFormatString="{0}"SelectMethod="GetCategories"

TypeName="Categories"UpdateMethod="UpdateCategory">

<DeleteParameters>

<asp:ParameterName="categoryid"Type="Int32"/>

</DeleteParameters>

<UpdateParameters>

<asp:ParameterName="categoryid"Type="Int32"/>

<asp:ParameterName="categoryname"Type="String"/>

<asp:ParameterName="parentcategoryid"Type="Int32"/>

<asp:ParameterName="sortorder"Type="Int32"/>

</UpdateParameters>

<InsertParameters>

<asp:ParameterName="categoryname"Type="String"/>

<asp:ParameterName="parentcategoryid"Type="Int32"/>

<asp:ParameterName="sortorder"Type="Int32"/>

</InsertParameters>

</asp:ObjectDataSource>

<atlas:ScriptManagerid="MasterScriptManager"EnableScriptGlobalization="false"runat="Server">

</atlas:ScriptManager>

<cc1:reorderlistid="ReorderList1"runat="server"allowreorder="True"callbackcssstyle="callbackStyle"

datakeyfield="categoryid"datasourceid="CatKidsDataSource"sortorderfield="sortorder"ItemInsertLocation="End">

<ItemTemplate>

<divclass="itemArea">

<b>Category:</b><asp:LabelID="Label4"runat="server"Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("CategoryName"))) %>'></asp:Label>

</div>

</ItemTemplate>

<ReorderTemplate>

<asp:PanelID="Panel2"runat="server"CssClass="reorderCue">

</asp:Panel>

</ReorderTemplate>

<InsertItemTemplate>

<divstyle="padding-left:25px; border-bottom:thin solid transparent;border-top:thin solid transparent;">

<asp:PanelID="panel1"runat="server"DefaultButton="Button1">

Insert a new Category here<br/>

Category Name<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="Category"

ErrorMessage="Please enter a question"ValidationGroup="Insert">*</asp:RequiredFieldValidator>

<asp:TextBoxID="Category"Text='<%# Bind("CategoryName")%>'runat="server"></asp:TextBox><br/>

Parent Category:<br/>

<asp:DropDownListID="ParentName"runat="server"DataSourceID="CatList2DataSource"

DataTextField="CategoryName"DataValueField="CategoryID"ValidationGroup="Insert"AppendDataBoundItems="True"SelectedValue='<%# Eval("ParentCategoryID") %>'>

<asp:ListItemValue="0">Top Level</asp:ListItem>

</asp:DropDownList><asp:ObjectDataSourceID="CatList2DataSource"runat="server"OldValuesParameterFormatString="original_{0}"

SelectMethod="GetCategories"TypeName="Categories"></asp:ObjectDataSource>

<asp:ButtonID="Button1"runat="server"CommandName="Insert"Text="Add"ValidationGroup="Insert"></asp:Button>

</asp:Panel>

</div>

</InsertItemTemplate>

</cc1:reorderlist>

<asp:ObjectDataSourceID="CatKidsDataSource"runat="server"InsertMethod="AddCategory"

OldValuesParameterFormatString="original_{0}"SelectMethod="GetCategoriesByParent"

TypeName="Categories"UpdateMethod="UpdateCategory"DeleteMethod="Deletecategory">

<UpdateParameters>

<asp:ParameterName="categoryid"Type="Int32"/>

<asp:ParameterName="categoryname"Type="String"/>

<asp:ParameterName="parentcategoryid"Type="Int32"/>

<asp:ParameterName="sortorder"Type="Int32"/>

</UpdateParameters>

<SelectParameters>

<asp:ControlParameterControlID="DropDownList1"Name="parentid"PropertyName="SelectedValue"

Type="Int32"/>

</SelectParameters>

<InsertParameters>

<asp:ParameterName="categoryname"Type="String"/>

<asp:ParameterName="parentcategoryid"Type="Int32"/>

<asp:ParameterName="sortorder"Type="Int32"/>

</InsertParameters>

<DeleteParameters>

<asp:ParameterName="categoryid"Type="Int32"/>

</DeleteParameters>

</asp:ObjectDataSource>


I had the same problem. To get around the problem I added some hidden fields that the dropdown updated, and bound the hidden fields and this worked for me:

<InsertItemTemplate>

<!-- bottom border is workaround for IE7 Beta issue where bg doesn't render -->

<divstyle="padding-left:25px; border-bottom:thin solid transparent;">

<asp:PanelID="panel1"runat="server"DefaultButton="Button1">

<asp:DropDownListID="DDLResources"runat="server"

OnPreRender="DDLResources_PreRender"ValidationGroup="Add"OnSelectedIndexChanged="DDLResources_SelectedIndexChanged"/>

<asp:HiddenFieldID="hdnResourceId"runat="server"value='<%# Bind("ResourceId") %>'/>

<asp:HiddenFieldID="hdnResourceCode"runat="server"value='<%# Bind("ResourceCode") %>'/>

<asp:ButtonID="Button1"runat="server"CommandName="Insert"Text="Add"ValidationGroup="Add"/>

</asp:Panel>

</div>

</InsertItemTemplate>

DropDownExtender: How can I set the text of downlist?

Hi,

I need your kindly help.When I try to use DropDownExtender just as following:

<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Always" RenderMode="Inline">
<ContentTemplate>
<cc1:DropDownExtender ID="dropdownextender" runat="server" Enabled="true" TargetControlID="fromTime" DropDownControlID="calender" >
</cc1:DropDownExtender>
<asp:Calendar ID="calender" runat="server" OnSelectionChanged="calender_SelectionChanged" ></asp:Calendar>
<asp:DropDownList ID="fromTime" runat="server" AutoPostBack="false" Width="90%">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="calender" />
</Triggers>
</asp:UpdatePanel>

protected void calender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Text = calender.SelectedDate.ToString();
}

Although I can get the SelectedDate, but formTime.Text is “”all the time.Is there anything wrong? How can I set the text?

Many Thanks&&Best Reguards

Nicorn

Resolved.Big Smile

protected void fromcalender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Items.Clear();
string[] date = fromcalender.SelectedDate.ToString().Split(' ');
fromTime.Items.Add(new ListItem(date[0], date[0]));
}


Big Smile Fixed ^_^

protected void fromcalender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Items.Clear();
string[] date = fromcalender.SelectedDate.ToString().Split(' ');
fromTime.Items.Add(new ListItem(date[0], date[0]));
}

DropDownExtender: Edit TextBox attached to DropDownExtender

Is there a way to edit the textbox that is attached to the dropdownextender.

1<asp:TextBox ID="txtLocation" runat="server" OnTextChanged="txt_TextChanged" />
2 <cc1:DropDownExtender ID="DropDownExtender1" runat="server" DropDownControlID="Panel1" TargetControlID="txtLocation">
3 </cc1:DropDownExtender>

I have tried adding a textbox to Panel1 but it disappears as soon as i click on it.

Marty

My guess would be that once the TextBox in the Panel receives focus, the Panel loses focus, and that causes the Extender's script to think that it should close the Panel.

It sounds like you need a Panel that doesn't auto-close and you have to manually close. That way you can do data entry on the Panel.


And how is that done?
Popup window, modal dialog, roll your own iframe or floating div...

Hi ,

I am facing same problem.Can you please tell me how can I solve it?

Many thanks,

Ramesh.


Any solution about this issue ?