Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

Have landed into a scenario, experts might be able to assist me.
Have an aspx page which is composed of various user controls.
In one of the user controls, I have added a dropdownlist and few images.
On click of one of the images, another aspx page opens up as a popup. Some operations happen there and on the OK button click of the popup page, a name has to be saved in the DB. At the same time the dropdownlist present in the user control has to be populated with the same name. Saving, retrieval from the DB, all are happening quite fine. But the dropdownlist is not populating. I googled and found out that if I place my dropdownlist inside an Update Panel and on a hidden button click, If I try to populate the dropdownlist, it will be.Have tried all these stuffs, but it just doesn't happen.
Below are my codes. Please have a look and try to assist.

Code for dropdownlist in the user control:

XML
<asp:UpdatePanel ID="customUpdatePanel" runat="server">
<ContentTemplate>
<asp:DropDownList ID="dropDownListView" runat="server">
<asp:ListItem Value="0" Text="Standard"></asp:ListItem>
</asp:DropDownList>
<input type="button" ID="Button1" runat="server" value="" style="display:block" onserverclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:ImageButton ID="btnNew" runat="server" Height="20px" ImageUrl="~/Images/new.png" Width="20px" OnClientClick="ShowPopup();" />

JavaScript
function ShowPopup() {
    var returnValue = window.open("ViewColumnOptions.aspx", "ViewColumnOptions", "height=400,width=600");
    if (returnValue==true) {
        document.getElementById("Button1").click();
    }
}


OK button click code of the popup page:
C#
protected void btnOK_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtViewName.Text))
{
obj.SaveReportViewToDataBase(saveObj);
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "Close();", true);
}
}

JavaScript
function Close() {
    window.returnValue = true;
    window.close();


Methods in usercontrol.ascx.cs:
C#
public void Button1_Click(object sender, EventArgs s)
       {
           PopulateOtherViews();
       }

       public void PopulateOtherViews()
       {
           SaveReportViewFilter<ReportFilterBase> newObj = new SaveReportViewFilter<ReportFilterBase>();
           ViewColumnOptions vwobj = new ViewColumnOptions();
           newObj.UserName = vwobj.Page.User.Identity.Name;
           SaveReportView<ReportFilterBase> obj2 = new SaveReportView<ReportFilterBase>();
           DataTable dt = obj2.GetSaveReportViewFromDataBase(newObj);
           dropDownListView.DataSource = dt;
           dropDownListView.DataTextField = dt.Columns[0].ToString();
           dropDownListView.DataValueField = dt.Columns[0].ToString();
           dropDownListView.DataBind();
       }


Everything seems allright..but the dropdownlist just doesn't populate.
Experts please help or provide some pointers.

Regards
Anurag
Posted
Updated 15-Jul-13 8:46am
v2
Comments
Sergey Alexandrovich Kryukov 15-Jul-13 13:19pm    
What do you mean "behaves as null"? You could always run it under the debugger and see if it is null or not.
—SA
Anurag Sinha V 16-Jul-13 2:25am    
"Behaves as null" means that I have debugged it numerous times and yet it is null...dropdownlist in the user control itself becomes null...ANy pointers would certainly help Mr. SA.. :)
-anurag
Yuriy Loginov 15-Jul-13 13:42pm    
the line: document.getElementById("Button1").click(); may be causing your whole page to reload. Check to see that btnOK_Click gets called after Page_Load. If btnOK_Click get called before Page_Load this means that the values that you add to the drop down get wiped out when the page reloads. As a suggestion I would trigger the page refresh without using a hidden button and by simply calling form1.submit(); Then inside your Page_Load add a call to refresh the dropdown values
Anurag Sinha V 16-Jul-13 2:42am    
btnOK_Click gets called after the Page_Load of the usercontrol..If my button OK was a HTML control, i could get the code to work, but the ASP.NET button control is giving me problems...so as per me, the hidden button stuff is the only method left...do you have some sample code or something?
-regards
Yuriy Loginov 16-Jul-13 9:34am    
I would make sure that no other part of your code is updating the drop down as well. Also add return false to your image button click to prevent additional postbacks
<asp:ImageButton ID="btnNew" runat="server" Height="20px" ImageUrl="~/Images/new.png" Width="20px" OnClientClick="ShowPopup(); return false;" />
Inside your show popup method all you need is this
if (returnValue)
your_form_name.submit();
Then finally instead of adding values to the drop down from the database try some hardcoded values to see if that works




This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900