I have a page with dropdown list
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%">
<Behaviors>
<ig:Sorting>
</ig:Sorting>
</Behaviors>
</ig:WebDataGrid>
code behind is
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityName.Text = DropDownList1.SelectedItem.Text;
}
For somereason the label is never updated the event selectedindexchanged is not firing at all I need to add a dynamic grid in this event. Any clue?
You need to add AutoPostBack on the dropdown
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
You can actually tell that there is no post back when you do not have the AutoPostBack=true attribute.
set dropdownlist property AutoPostBack="true"
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
Related
To be brief, I need the Textbox with ID="textComments" to only appear when the dropdown option of 'Other' is selected from the dropdown, and then disappear if another selection is made. I could do this with JS but it needs to be in C#.
<asp:DropDownList runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
<asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
<asp:ListItem Value="Website" Text="Website"></asp:ListItem>
<asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
<asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>
<asp:label runat="server" ID="lblComments" AssociatedControlID="textComments" CssClass="textLabel">Comments:</asp:label>
<asp:TextBox runat="server" MaxLength="200" TextMode="MultiLine" Columns="40" Rows="4" ID="textComments" Wrap="true" CssClass="textComments"></asp:TextBox>
And help would be greatly appreciated.
Make the DropDownList first AutoPostBack=true
handle it's SelectedIndexChanged-event
Switch visibility of both controls there
aspx:
<asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="dropEnquiryType_Changed" runat="server" ID="dropEnquiryType" CssClass="dropdownRequestList">
<asp:ListItem Value="Customer Services" Text="Customer Services"></asp:ListItem>
<asp:ListItem Value="Website" Text="Website"></asp:ListItem>
<asp:ListItem Value="Contract" Text="Contract Hire"></asp:ListItem>
<asp:ListItem Value="Other" Text="Other"></asp:ListItem>
</asp:DropDownList>
codebehind:
protected void dropEnquiryType_Changed(Object sender, EventArgs e)
{
lblComments.Visible = dropEnquiryType.SelectedValue == "Other";
textComments.Visible = lblComments.Visible;
}
If you absolutely have to do this within C#, then a simple check in PreRender should be sufficient:
textComments.Visible = (dropEnquiryType.SelectedValue == "Other");
This will also require you to set AutoPostback on dropEnquiryType, though, which uses ... JavaScript!
I have a few buttons within an update panel. I have now been asked to replace the buttons with
a drop down list . I see that the selectedindexchanged event on the drop down list is much slower
than the button click event. I have the code below. Can anyone point me as to why it is happenning ?
or what I can do to make the selectedindexchanged event response faster .
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<div class="ui-widget-header" style="display: inline;">
<asp:Label ID="lblRefresh" runat="server" Text="Refresh Interval:" CssClass="label"
ForeColor="Black"></asp:Label>   
<asp:LinkButton ID="btnOFF" runat="server" OnClick="btnOFF_Click" Text="Off">
</asp:LinkButton> 
<asp:LinkButton ID="btn60SEC" runat="server" OnClick="btn60SEC_Click" Text="1Min">
</asp:LinkButton> 
<asp:LinkButton ID="btn5MIN" runat="server" OnClick="btn5MIN_Click" Text="5Min">
</asp:LinkButton> 
<asp:LinkButton ID="btn10MIN" runat="server" OnClick="btn10MIN_Click" Text="10Min">
</asp:LinkButton> 
<asp:LinkButton ID="btn15MIN" runat="server" OnClick="btn15MIN_Click" Text="15Min">
</asp:LinkButton>
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlRefresh" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Well what seems to work for me right now is to set AutoPostback = "true" for the dropdownlist .
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
I had the same problem and I found that the problem is with _destroyTree. Check it here (https://siderite.dev/blog/very-slow-updatepanel-refresh-when.html).
At the moment, I have a GridView with the following in the ItemTemplate:
<asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit">
<asp:Label ID="Label6x" runat="server" Text='<%# Bind("progress_full") %>' /></asp:LinkButton>
This works fine and when I click on it, it displays the EditTemplate which currently contains the following:
<asp:DropDownList ID="DropDownList3" runat="server"
SelectedValue='<%# Bind("progress") %>'>
<asp:ListItem Value="0">In queue</asp:ListItem>
<asp:ListItem Value="1">Being worked on</asp:ListItem>
<asp:ListItem Value="2">Complete</asp:ListItem>
</asp:DropDownList><br />
<asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update" Text="Update" />
How can I get the dropdown to automatically execute the Update command when it is changed, instantly returning back to the ItemTemplate, instead of me making the change to the DropDown and having to click Update?
You add AutoPostBack="true" to your DropDownList and set OnSelecIndexChanged="DropDownList1_SelectedIndexChanged"
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//execute here your update
......
}
Hey guys check this out ...
<asp:TabContainer ID="jkhgjkgh" runat="server">
<asp:TabPanel ID="jkkljhgh" runat="server" HeaderText="sdkl;fgjl;kgjdf">
<ContentTemplate>
<asp:Button ID="jhgkjgh" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="jkgh" runat="server" HeaderText="gjdkl;gjdf;g" Visible="false">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownSelect">
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
</asp:DropDownList>
</ContentTemplate>
</asp:TabPanel>
nothing crazy ... just a tabcontainer with a couple of panels on it the second is hidden.
now we go to the code behind ...
protected void Button1_Click(object sender, EventArgs e)
{
TabPanel p = new TabPanel();
p.ContentTemplate = jkgh.ContentTemplate;
jkhgjkgh.Tabs.Add(p);
}
protected void dropDownSelect(object sender, EventArgs e)
{
int i = 0;
}
Here's where it all goes horribly wrong ...
I click the button on the first tab panel to create a new tab that has the template defined in my hidden panel, i then go to that panel and change the selection in the drop down ....
It does a postback but the drop down event is never raised ....
Any ideas ???
The problem is that you cant dynamically copy the hidden templated tabpanel and add a new one in to the collection.
Apparently the tabcontainer control doesn't allow for this without a lot of "hacking around".
I'm not entirely sure why but it seems that ITemplate types don't clone well for event handling.
I think it might be because your TabContainer does not have AutoPostBack set to true.
this is my radio button list:
<asp:RadioButtonList runat="server" ID="rdlTest" OnSelectedIndexChanged="rdlTst_selectedChange">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:RadioButtonList
this is the code behind:
protected void rdlTst_selectedChange(object sender, EventArgs e)
{
Response.Write("hello");
}
it's not firing the event for some reason
You need to add AutoPostBack = "true" onto the definition of the RadioButtonList.
<asp:RadioButtonList runat="server" ID="rdlTest" AutoPostBack="true" OnSelectedIndexChanged="rdlTst_selectedChange">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:RadioButtonList>