I have an aspx page in which I have Ajax UpdatePanel which has a AJAX Tabcontainer which has 5 tab. In First tab I have a DropDownList for ProductID. In the second tab I have used a UserControl whose parameter needs to be reflected based on productID. I want to Access the DropDownList ProductID in the user control which I am not getting. Part of my code is
DropDownList IDList = (DropDownList)(this.Parent.FindControl("ProductID");
this is not working and I am getting NULL. I also have Tried
DropDownList IDList = (DropDownList)(this.Page.FindControl("ProductID");
Please tell me how I can do this.
As asked Part of necessary code is
<asp:UpdatePanel ID="UpdatePanelTankFormula" runat="server">
<ContentTemplate>
<asp:tabcontainer id="TabContainerTankFormula" AutoPostBack="true" runat="server" OnClientActiveTabChanged="clientActiveTabChanged" activetabindex="0" style="width:100%;">
<asp:TabPanel ID="InputDataTab" runat="server" HeaderText="Data Input">
<ContentTemplate>
<asp:DropDownList id="TankNameCombo" DataTextField="TankName" runat="server" AutoPostBack="true" DataValueField="customertankid" width="200px" onclick="javascript:SetHiddenField();"> </asp:DropDownList>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="LacticAcidAdditionTab" runat="server" HeaderText="Lactic Acid Addition">
<ContentTemplate>
//My user control
<UC:TankNote runat="server" ID="LaticTankNotesUC" GetNoteType="LAC" MEQMode="False"></UC:TankNote>
</ContentTemplate>
</asp:TabPanel>
</asp:tabcontainer>
<ContentTemplate>
</asp:UpdatePanel>
Now in the Code Behind of this User Control I want to access this DropDownList, which I am not getting. For the fix I have define a Public function that return the value of this list. But its a fix not solution.
You will have something like this in tab control.
<cc1:TabContainer ID="TabContainer1" runat="server">
<cc1:TabPanel ID="TabPanel1" runat="server">
<ContentTemplate>
<asp:DropDownList id="dropdownlist1" runat="Server"/>
</ContentTemplate>
</cc1:TabPanel>
So first you need to find tabPanel1 then find dropdownlist1 like following.
TabContainer TabContainer1= (TabContainer)(this.Page.FindControl("TabContainer1");
if (TabContainer1!=null){
TabPanel TabPanel1= (TabPanel)(this.TabContainer1.FindControl("TabPanel1");
if(TabPanel1 !=null){
DropDownList dropdownlist1= (DropDownList)(this.TabPanel1.FindControl("dropdownlist1");
}}
Related
I have an UpdatePanel with a Repeater inside a Panel. By clicking in one of the cells of the repeater, 2 detailed Views (Gridview, Formview - each one in a UpdatePanel) are displayed based on the repeater's argument passed in a LinkButton.
While the Gridview is displaying fine, the FormView is not when Updating their UpdatePanels. All the DataBindings should be working correctly as I had been running the app for a year - but without the UpdatePanels! I am using them for the first time and must be missing something.
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Always">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical" Height="600px">
<asp:Repeater runat="server" id="RepeaterKalendar">
<ItemTemplate>
...
<asp:LinkButton ID="ButtonSelect" runat="server" CommandArgument = '<%# Eval("date") %>' Text='<%# Bind("TAG") %>' OnClick="GetDetails"/>
...
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel_Grid" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:GridView runat="server" ID="Grid_Details" OnSelectedIndexChanged="IndexChanged">
...
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="UpdatePanel_Form" UpdateMode="Conditional">
<ContentTemplate>
<asp:FormView runat="server" ID="Form_Details" DefaultMode="Edit"">
<EditItemTemplate>
...
</EditItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
Code behind for LinkButton Click
protected void GetDetails(object sender, EventArgs e)
{
LinkButton LinkButton1 = (sender as LinkButton);
string commandArgument = LinkButton1.CommandArgument;
BuildDetailsViewReport(Convert.ToDateTime(commandArgument));
BuildDetailsViewList(Convert.ToDateTime(commandArgument));
UpdatePanel_Grid.Update();
UpdatePanel_Form.Update();
}
UpdatePanel_Form.Update() does not update the FormView and causes even that the GridView is not updated. If I remove that command from the code, the GridView is uploaded correctly.
Any help is appreciated.
Martin
I have below structure in my asp.net application.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="overlay"></div>
<asp:Panel ID="pnlMain" runat="server" Visible="true">
<asp:UpdatePanel ID="upProfile" runat="server" UpdateMode="Always">
<ContentTemplate>
<div>
<table>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upAttachment" runat="server" UpdateMode="Always">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlSuccessMessage" runat="server" >
<asp:Label ID="lblSuccessMessage" runat="server"></asp:Label>
</asp:Panel>
I have different textfields and dropdowns in the table of upProfile updatepanel and file upload control in upAttachment updatepanel. Now when I select one radio from the same update panel, I am getting below error and the upAttachment does not show up on page.
Uncaught Error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'MainContent_upAttachment'. If it is being updated dynamically then it must be inside another UpdatePanel.
I have searched a lot and tried below different things, but still it is not working
1. Set the upAttachment UpdateMode to Conditional.
- In this case, it does not throw error, but the file upload control which is inside that updatepanel, it does not show up
2. Place the upAttachment updatepanel inside another updatepanel, but that too is not working.
I don't know what to do in this case. Can anyone help me on this?
I have a page name ask.aspx
I have 4 list views in that page which are binding at the time of page load event.
now when ever i click on the items of list view i get the whole page refreshed.
I have used the update panel but for some reasons it is not working
The code for the same is given below.
aspx page
enter code here
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend><asp:Label ID="Label1" runat="server"></asp:Label></legend>
<ul class="tags">
<asp:ListView ID="ListView1" runat="server" OnItemCommand="ListView1_ItemCommand" >
<ItemTemplate>
<li><asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("CategoryId") %>'><%# Eval("Name") %></asp:LinkButton></li>
</ItemTemplate>
</asp:ListView>
</ul>
</fieldset>
</ContentTemplate>
<Triggers></Triggers>
</asp:UpdatePanel>
ending the content template and update panel.
similarly for the other three listviews.
at cs page
some calculations are taking place.
Now i dont want the page to refresh every time.
what should be done.
please suggest.
Remove childrenastrigger property and set updatemode=always
All I wish to do is simply click a button and the text in a textbox is automatically added as an item in the listbox. Shouldn't this be straight forward? Whilst debugging, the item is added and I can see the text by watching ListBox1.Items[0], but nothing is displayed in the web page. I had the same problem which i did not solve, in a console application! Can some one please guide me to what I am doing wrong?
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(TextBox1.Text));
}
Many thanks
Edit:
In a past project, I used the DataSource property, which worked perfectly. I have never yet managed to use the add Items! May be there is some sort of refresh or update?
Page code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="295px"></asp:ListBox>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Looks like your listbox is outside of the update panel. Pop it inside the update panel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="AddItem" />
</ContentTemplate>
</asp:UpdatePanel>
You have to move the ListBox into the UpdatePanel, otherwise it will not be updated.
The reason for that is, that ASP.NET is sending the whole HTML of the UpdatePanel back to the client. Since the ListBox is not part of the UpdatePanel, it won't be updated.
I have an UpdatePanel in a Repeater.
There are a few CheckBoxes in the UpdatePanel with AutoPostBack="true"
There is a Label in the UpdatePanel. I set the Text value of the label in RepeaterName_ItemDataBound as it runs on every item generated.
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource" OnItemDataBound="R1_ItemDataBound">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:Label ID="DateTimeLabel2" runat="server" Text="Label"></asp:Label>
<asp:Panel ID="panID" CssClass="actionicon_normal actionicon_compare" runat="server">
<%#XPath("ID")%>
<asp:CheckBox ID="chkID" runat="server" AutoPostBack="true" />
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
I want the CheckBoxes to automatically update the UpdatePanel as there were no repeater around, but possibly because the OnItemDataBound does not fire on every AsyncPostBack, nothing gets updated.
What is the proper way to do this?
In the onclick (JavaScript) call this function __doPostBack('idOfUpdatePanel', '');
Javascript and UpdatePanel