ImageButton in Updatepanel fires only on first Page Load - c#

I have the following Updatepanel:
<asp:UpdatePanel ID="upPopUps" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="panelOverlay" runat="server" class="Overlay" Visible="false">
</asp:Panel>
<asp:Panel ID="panelPopUpPanel" runat="server" class="PopUpPanel" Visible="false"
BorderStyle="Solid" BorderWidth="5px" Height="250px">
<table style="width: 100%; height: 100%; border-bottom: solid 2; border-top: solid 2;
border-left: solid 2; border-right: solid 2;">
<tr>
<th style="width: 100%; padding-left: 10px;" colspan="2">
<asp:PlaceHolder ID="PopupHeader" runat="server"></asp:PlaceHolder>
</th>
<th>
<asp:ImageButton id="cmdClosePopUp" runat="server" src="../Navigation/PopupImages/Close.png" alt="Close Popup"
OnClick="ClosePopup" align="right" />
</th>
</tr>
<tr class="border_top">
<td colspan="3">
</td>
</tr>
<tr style="height: 80%">
<td align="center">
<asp:PlaceHolder ID="PopupMessage" runat="server"></asp:PlaceHolder>
</td>
</tr>
<tr style="height: 10%">
<td colspan="3" style="padding-left: 10px;">
<input type="hidden" id="StartDivID" value="0" runat="server" />
<input type="hidden" id="NewsCount" value="" runat="server" />
<asp:ImageButton runat="server" id="btn_ok" src="../Navigation/PopupImages/Ok_Button.jpg" alt="Close Popup"
OnClick="ClosePopup" align="right" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
My problem is that if i click on one of these two Buttons after PageLoad it works fine.
Through $(document).ready(function() i refresh the Page every 60 seconds. The PopUp pops up, but the Buttons do not fire anymore.
$(document).ready(function() {
setInterval("RefreshGrid()", 60000);
});
function RefreshGrid() {
var WebGrid1 = ISGetObject("WebGrid1");
WebGrid1.Refresh();
}
Do someone has an idea, where could be the problem? Why is it only working on the first pageload?

There's a reserved function called pageLoad that runs at every postback. Bind your events inside it.
function pageLoad() {
$('#btn_ok, #cmdClosePopUp').click(ClosePopup); //Something like this.
}
It feels like you're losing the link to the handlers when you refresh. This should fix that.

Related

Table row server side click in repeater?

I have a repeater which has table as per below code and I need to send param to code behind when table row is clicked.
At the moment I am passing it on LinkButton1 click.
I have also tried wrapping in LinkButton but it's not working
How do I do this?
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" OnItemDataBound="Repeater1_ItemDataBound" OnItemCreated="Repeater1_ItemCreated">
<HeaderTemplate>
<table class="table table-striped table-bordered dttable dataTable no-footer" style="border-style: solid; border-color: rgb(252, 253, 250); text-align: center; font-weight: 700; width: 100%;" id="JsDataTable" role="grid" aria-describedby="JsDataTable_info">
<thead style="width: 100%">
<tr style="color: #fff; width: 100%;">
<td id="tdSr">Sr</td>
<td id="tdCode" style="white-space: nowrap;">
<asp:LinkButton ID="lnCode" runat="server" CommandName="CourseNo" CssClass="linkHeader">Code<i class = "fa fa-fw fa-sort" ></i></asp:LinkButton>
</td>
<td id="tdName" style="width: 50%; white-space: nowrap; text-align: left;">
<asp:LinkButton ID="lnName" runat="server" CommandName="VName" CssClass="linkHeader">Name<i class = "fa fa-fw fa-sort" ></i></asp:LinkButton>
</td>
<td id="tdType" style="width: 20%">
<asp:LinkButton ID="lnType" runat="server" CommandName="VType" CssClass="linkHeader">Type<i class = "fa fa-fw fa-sort" ></i></asp:LinkButton>
</td>
</tr>
</thead>
<tbody style="width: 100%">
</HeaderTemplate>
<ItemTemplate>
<tr id="trID" runat="server" class="box" style="height: 30px; color: #08516F; vertical-align: middle;">
<td style="color: #004457; border-right: 1px solid #004457; vertical-align: middle;" class="labelTxt">
<asp:HiddenField ID="hfAllowSubscription" runat="server" Value='<%#Eval("AllowSubscription") %>' />
<asp:Label ID="lblSR" runat="server"></asp:Label>
</td>
<td style="color: #004457; border-right: 1px solid #004457; vertical-align: middle;">
<%#Eval("CourseNo") %>
</td>
<td style="color: #004457; border-right: 1px solid #004457; text-align: left !important; vertical-align: middle;">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="PlayPrev" CommandArgument='<%#Eval("Id") %>' Text='<%#Eval("Name") %>' CssClass="name"></asp:LinkButton>
</td>
<td style="color: #004457; border-right: 1px solid #004457; vertical-align: middle;">
<asp:Label Text='<%#Eval("VType") %>' runat="server" ID="lblType" CssClass="lblType" Style="font-family: 'Segoe UI semiBold' !important;"></asp:Label>
<span id="lblsubtype" runat="server" class="subtype_color T"></span>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
<div id="repeatorEmptyRow" runat="server" style="text-align: center; color: red;">
No matching records found
</div>
</FooterTemplate>
</asp:Repeater>
I'm guessing you want the value of the CommandArgument in Repeater1_ItemCommand. But if you try to cast the sender to a LinkButton that will not work because the Sender is the Repeater, not the button inside.
So cast the CommandSource and get the correct value.
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
LinkButton lb = e.CommandSource as LinkButton;
Label1.Text = lb.CommandArgument;
}
You cannot bind a tr click directly, so you have to use a trick. You can use jQUery to set the click of the LinkButton to the row itself.
<table border="1" id="Repeater1Table">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<tr>
<td>Click here</td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="PlayPrev" CommandArgument='<%#Eval("Id") %>' Text='<%#Eval("Name") %>' CssClass="name"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<script type="text/javascript">
$(document).ready(function () {
$("#Repeater1Table tr").each(function () {
var href = $(this).find(".name").prop("href").split(":")[1];
$(this).attr("onclick", href);
});
});
</script>

.NET ListView footer controls

New to using the ListView control and I'm trying to retrieve the value of some textboxes in the layout template. Here's my aspx code:
<asp:ListView
ID="lvFundingSummary"
OnItemCommand="lvFundingSummary_onItemCommand"
OnItemDataBound="lvFundingSummary_ItemDataBound"
runat="server" >
<EmptyDataTemplate>
<table
id="Table1"
runat="server"
style="background-color: #FFFFFF;
border-collapse: collapse;
border-color: #999999;
border-style:none;
border-width:1px;">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr>
<td style="width: 50%; text-align:left; padding-top: 5px; padding-bottom:5px;">
<asp:Label ID="lblResearchArea" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PlName")%>' />
</td>
<td style="width: 30%; text-align:right; padding-top: 5px; padding-bottom:5px;">
<asp:Label ID="lblFundingGross" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FundingGross", "{0:c}")%>' />
</td>
<td style="width: 20%; text-align:right; padding-top: 5px; padding-bottom:5px;">
<asp:Label ID="lblGross" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AllGross", "{0:c}")%>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" style="width: 90%" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server" width="100%">
<table
ID="itemPlaceholderContainer"
runat="server"
style="width: 98%">
<tr id="TrHeading" runat="server">
<th id="Th1" style="width: 50%; text-align:left;" runat="server">
Research Area</th>
<th id="Th2" style="width: 30%; text-align:right;" runat="server">
Gross</th>
<th id="Th3" style="width: 20%; text-align:right;" runat="server">
All Gross</th>
</tr>
</table>
<div style="overflow-y:scroll; height:400px;">
<table style="border: 10px; width: 100%">
<tr ID="itemPlaceholder" runat="server"></tr>
</table>
</div>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server"
style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
</td>
</tr>
<tr id="TrFooter" runat="server">
<td style="width: 50%; text-align:left;">
<b>Total(s)</b>
</td>
<td id="TdTotal" style="width: 30%; text-align:right;">
<b>
<asp:Label ID="lblTotalFunding" runat="server" /></b>
</td>
<td id="TdTotal" style="width: 20%; text-align:left;">
<b>
<asp:Label ID="lblTotalGross" runat="server" /></b>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
in the lvFundingSummary_PreRender event, I'm trying to access the control as such:
Label lbTotFund = this.lvFundingSummary.FindControl("TrFooter").FindControl("lblTotalFunding") as Label
but that's not working. I know this should be a snap, just can't quite seem to find it.
According to this post, use
var lbTotFund = lvFundingSummary.FindControl("lblTotalFunding") as Label;
in lvFundingSummary_LayoutCreated event, it should do the work

JavaScript Function

I want to store TextBox value in HidenField and i am calling javascript function on button click function is calling getting message Hi but... textBox getting null....I am using asp.net TextBox and also i have tried with HTML textBox also but same scenario happing in both the case...Actually HTML code using in Ajax Tab Container may be this problem ...
How to solve such type of problem
function f11() {
alert("Hi")
alert("hi..." + document.getElementById("txthtmltextbox").value)
document.getElementById("txtuncheaderHF").value = document.getElementById("txthtmltextbox").value;
document.getElementById("txtrootFolderHF").value = document.getElementById("txthtmltextboxroot").value
}
This is my HTML code
<asp:Panel ID="pnlhfconfig" runat="server" Height="100%" Width="100%">
<table bordercolor="gainsboro" bgcolor="white" style="border-bottom-width: 1px; border-bottom-style: solid;
border-top-width: 1px; border-top-style: solid; border-left-width: 1px; border-left-style: solid;
border-right-width: 1px; border-right-style: solid; border-bottom-color: #8C8B83;
border-top-color: #8C8B83; border-left-color: #8C8B83; border-right-color: #8C8B83;"
id="TABLE2" language="javascript">
<tbody>
<tr>
<td colspan="3" bgcolor="#E5E5E5" height="20" class="topnav" style="font-size: 10px;
font-family: verdana">
<font style="color: #000000"><strong>
<asp:Literal ID="Literal4" runat='server' Text='HF Configuration'></asp:Literal>  </strong></font>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbluncheader" runat="server" Text='HotFolder UNCHeader'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextbox" name="txthtmltextbox" onblur="f1()" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<asp:RequiredFieldValidator ID="rfvuncheader" runat="server"
ErrorMessage="UNCHeader is required." ControlToValidate="txthtmltextbox" Display="None"
ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblrootfolder" runat="server" Text='Hot RootFolder'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextboxroot" name="txthtmltextboxroot" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<%-- <asp:TextBox ID="txtrootfolder" runat="server" MaxLength="50" Width="250px"></asp:TextBox>--%><asp:RequiredFieldValidator
ID="rfvUNH" runat="server" ErrorMessage="RootFolder is required." ControlToValidate="txthtmltextboxroot"
Display="None" ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table>
<tr>
<td>
<asp:Button ID="btnsave" OnClientClick ="f1()" runat="server" Text='Save' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" ValidationGroup="save" />
</td>
<td>
<asp:Button ID="btncancel" runat="server" Text='Cancel' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" />
</td>
</tr>
<tr>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="save" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</asp:Panel>
Hope you aware of JQuery and using JQuery, you will easily get inner control of panel. Because when your page is render on browser. Html code is something different then .NET(ASPX page).
You will get/set panel inner control value using below statement.
$("#<%=pnlhfconfig.ClientID %> input[id='<%= txtuncheaderHF.ClientID %>']").val($("#<%=pnlhfconfig.ClientID %> input[id='<%= txthtmltextbox.ClientID %>']").val());
You are using txthtmltextbox please check on console what is the actual ID of control while generating html.
Or use as
document.getElementById("<%= txthtmltextbox.ClientID%>").value

Asynchronously extend multiple CollapsiblePanels

I have a webpage that is setup like so:
There is a ListView that has an item for each record in one of our SQL tables. Each of these items has a CollapsiblePanel in it that can be expanded to show more detail about the given record.
My Issue:
When I expand one panel and then wait for it to complete...everything is okay. However, if I try to expand multiple of those collapsiblepanels at once (meaning before the first panel is completely expanded)...only the last panel expands showing its data.
My Question:
Is it possible to have each of these panels expand asynchronously? Seems silly that I have to wait for one panel to extend before I can extend another.
My aspx:
I modified this aspx a little bit by removing unneeded code to make it less confusing.
<asp:UpdatePanel ID="UpdPnlBGList" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div class="content-box">
<asp:Panel ID="pnlBGResult" runat="server">
<asp:ListView ID="lvSummary" runat="server" ItemPlaceholderID="placeholderBGList"
OnItemDataBound="lvSummary_ItemDataBound" OnItemCommand="lvSummary_ItemCommand">
<LayoutTemplate>
<table runat="server" id="tblList" cellpadding="0" cellspacing="0" border="0" style="table-layout: fixed;">
<tr id="placeholderBGList" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:UpdatePanel ID="UpdBgItemTemplate" runat="server" ChildrenAsTriggers="true"
UpdateMode="Conditional">
<ContentTemplate>
<div class="bgList">
<asp:Panel ID="pnlSummary" runat="server">
<table id="tblBgList" runat="server" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;
border-spacing: 0px;">
<tr>
<td class="imageColumn">
<asp:ImageButton ID="imgCollapsible" CssClass="first" ImageUrl="~/Images/branding/plus.gif"
runat="server" CommandName="ExpandCollapse" Style="cursor: pointer; padding-right: 5px;" />
</td>
<td width="600px">
<asp:Label ID="lblBGName" runat="server" Text='<%# Eval("BGName")%>' CssClass="bgName"></asp:Label>
<asp:Label ID="lblDatePosted" runat="server" CssClass="datePosted"></asp:Label>
</td>
<td colspan="2">
<div style="float: right;">
<asp:Label ID="lblAccountNumber" runat="server" CssClass="accountReview"></asp:Label>
<asp:Label ID="lblAccountNumberText" runat="server" CssClass="accountReview"></asp:Label>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td width="600px">
<asp:Label ID="lblBillToAddress" runat="server" Text='<%# Eval("BillToAddress")%>'
CssClass="billToAddress" Style="font-weight: bold;"></asp:Label>
</td>
<td>
<div style="float: right;">
<asp:ImageButton ID="imgViewAuthLetter" ImageUrl="~/Images/branding/document.jpeg"
CssClass="first" runat="server" OnClick="imgViewAuthLetter_Click" />
<asp:LinkButton ID="lnkAuthorizationLetter" runat="server" Text="View authorization letter"
class="link_button" OnClick="lnkAuthorizationLetter_Click" OnClientClick="dirtySuppress();"
OnPreRender="addTrigger_PreRender" />
</div>
</td>
<td width="70px" style="float: right;">
<div style="float: right;">
<asp:HyperLink ID="lnkExportImage" runat="server" ImageUrl="/Images/branding/export.jpg"
CssClass="hiperlinkExport" OnClick="dirtySuppress();" />
<asp:HyperLink ID="lnkExportText" runat="server" Text="Export" CssClass="hiperlinkExport"
OnClick="dirtySuppress(); precheckURL(this.href); return false;" />
</div>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px;">
<asp:Panel Style="margin-left: 50px;" ID="pnlDetails" runat="server">
<of:AccountNumberListControl ID="accountNumberList" runat="server"></of:AccountNumberListControl>
</asp:Panel>
<cc1:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlDetails"
CollapsedSize="0" Collapsed="True" ExpandControlID="imgCollapsible" CollapseControlID="imgCollapsible"
AutoCollapse="False" AutoExpand="False" ScrollContents="false" ImageControlID="imgCollapsible"
ExpandedImage="~/Images/branding/minus.gif" CollapsedImage="~/Images/branding/plus.gif"
ExpandDirection="Vertical" />
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" style="padding: 0px;">
<div class="itemSeperator" id="divItemSeperator" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:HiddenField ID="hdfAccountNumberListControlID" runat="server" Value="" />
<asp:HiddenField ID="hdfAccountNumerID" runat="server" Value="" />
</asp:Panel>
</div>
<of:CustomerSetupExportPopInControl ID="customerSetupExportPopIn" runat="server" />
</ContentTemplate>
My codebehind:
This is the code that is executed when you expand the panel. There are several controls that is populated.
private void ExpandBillingGroup(ListViewDataItem item)
{
Label accountNumberLabel;
Label accountNumberText;
HtmlControl itemSeperator;
AccountNumberListControl accountNumberList;
// set properties for fedex account number label and text.
accountNumberLabel = (Label)item.FindControl("lblAccountNumber");
accountNumberLabel.Text = "FedEx account number: ";
accountNumberLabel.CssClass = "fedExAccountNumberLabel";
accountNumberText = (Label)item.FindControl("lblAccountNumberText");
accountNumberText.Text = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberText.CssClass = "fedExAccountNumberText";
//set the properties for Export
var lnkExportImage = (HyperLink)item.FindControl("lnkExportImage");
lnkExportImage.Visible = true;
var lnkExportText = (HyperLink)item.FindControl("lnkExportText");
lnkExportText.Visible = true;
//When expanded populate Customer Setup Export control
customerSetupExportPopIn.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
//When expanded populate AccountNumberlistControl
accountNumberList = (AccountNumberListControl)item.FindControl("accountNumberList");
if (accountNumberList != null)
{
//since we make the AccountNumberListControl not visible on collapse we have to make it visible when we expand
accountNumberList.Visible = true;
//Set the properties
accountNumberList.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
accountNumberList.FedExAccountNumber = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberList.BillingGroupName = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBGName")).Text;
accountNumberList.BillToAddress = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBillToAddress")).Text;
accountNumberList.FirstItemNeedsToExpand = BillingGroupIsResolved;
accountNumberList.GetListOfAccountNumbers(lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString(), VendorID);
}
//set the properties for itemSepeartor
itemSeperator = (HtmlControl)item.FindControl("divItemSeperator");
itemSeperator.Attributes.Add("class", "itemSeperatorExpanded");
UpdatePanel upd = (UpdatePanel)item.FindControl("UpdBgItemTemplate");
upd.Update();
}
Thanks,
Holt
EDIT: Fixed grammar and title issues

Update dropdownlist on a Panel

I have two dropDownLists in a Panel that pops up. When i change one value in the first dropDownList i want to populate the seconde dropDownList with the value chosen in the first dropDownList. Like i have AutoPostBack = "true" the page is always refreshing and the PopUp disappears. When in fact i only want to update the panel on the PopUp.
I´m using AsyncPostBackTrigger.
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
Try this:
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
I had the similar problem and the key was in the part where I set the Items do Dropdown. When you set these Items it select the first one after page reload (with autopostback).
If this is your problem try this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillDropDown();
}
}

Categories