Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP.NET Dropdown control refresh

Posted on 2007-10-17
19
Medium Priority
?
2,397 Views
Last Modified: 2011-10-03
Codebase:
ASP.NET, VB

Synopsois:
i am creating a contact input screen in which i have a dropdown control called "Contact_Type" if the type the user wants to use is not available in the dropdown control they can push an "Edit" button next to the control to open a popup window that will allow them to manipulate the data that the control is bound to.

Problem:
After i have changed the data i.e. add/edit/delete i need to close the popup window and refresh the Contact_Type control to display the new values. I can not use a postback because the user may have unsaved information in th form, and i am trying to stay away from javascript. I tried to add a refresh button that calls the databind method of the dropdown control, but nothing happens. Ultimately it would be best to have the control refresh once the popup is closed automatically.
0
Comment
Question by:gigasausage
  • 10
  • 5
16 Comments
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20098800
The data that is being updated with the popup window is being stored on the server; correct?  So you'll need to post back on the closing event of the popup window.  You should not be loosing any data in the form on post back if you have view state enabled.

There are many different ways to go about this but I'd like to see the code used to open the popup window; javascript right?  If so, then you'll need to use javascript to fire of the post back on the closing event of the popup window.

Again, so code snippets of what your working with will help me pen-point the best approach to take.

Robert Fidler
Springfield, Missouri
0
 

Author Comment

by:gigasausage
ID: 20100544
here is the subroutine i use to call the new window. In the load event of the page i attach a button to the subroutine like this..

--on page load----
'Set btnAddType to open edit window
        OpenPopUp(btnAddType, "contypepop.aspx", "", 335, 300)
-----------------------

Public Shared Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String, ByVal windowName As String, ByVal width As Integer, ByVal height As Integer)
        Dim clientScript As String
        Dim windowAttribs As String

        'Building Client side window attributes with width and height.
        'Also the the window will be positioned to the middle of the screen
        windowAttribs = "width=" & width & "px," & _
                        "height=" & height & "px," & _
                        "left='+((screen.width -" & width & ") / 2)+'," & _
                        "top='+ (screen.height - " & height & ") / 2+'"

        'Building the client script- window.open, with additional parameters
        ClientScript = "window.open('" & PagePath & "','" & windowName & "','" & windowAttribs & "');return false;"
        'regiter the script to the clientside click event of the 'opener' control
        opener.Attributes.Add("onClick", ClientScript)
    End Sub
0
 

Author Comment

by:gigasausage
ID: 20100605
BTW..

the dropdown control is now in an AJAX update panel, on the second page of a tab control. I am using view state so i can do a postback to the page if necessary. Just dont know how to fire the postback from another window when it closes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
KPMT-Technician earned 500 total points
ID: 20101572
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine( @"var opnPopup;" );
sb.AppendLine( @"var iIntervalID;" );
sb.AppendLine( @"" );
sb.AppendLine( @"function showPopup( url, name, details) {" );
sb.AppendLine( @"opnPopup = window.open(url, name, details);" );
sb.AppendLine( @"iIntervalID = window.setInterval(isClosed(), 100);" );
sb.AppendLine( @"}" );
sb.AppendLine( @"" );
sb.AppendLine( @"function isClosed() {" );
sb.AppendLine( @"if (window.opnPopup.closed){" );
sb.AppendLine( String.Format( @"{0}", this.GetPostBackEventReference( DropDownList1, "args" ) ) );
sb.AppendLine( @"window.clearInterval(iIntervalID);" );
sb.AppendLine( @"}" );

this.ClientScript.RegisterClientScriptBlock( this.GetType(), "PopupControler", sb.ToString(), true );

This is not tested but should get you in the right direction.

Robert Fidler
0
 

Author Comment

by:gigasausage
ID: 20102934
im was getting a 'useless setInterval call (missing quotes arround argument?)' error on

sb.AppendLine( @"iIntervalID = window.setInterval(isClosed(), 100);" );

i put single quotes arround 'isclosed()' and the error went away, but it still does not refresh the dropdown

0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20103038
Try catching the post back and forcing the refresh of data.
0
 

Author Comment

by:gigasausage
ID: 20103095
there is no postback happening on page 1 to catch. According to your code... If the interval is not checking to see if the 2nd page is closed or not, then the postback will never occur, which is what is happening right now. how do you get the "isclosed()" back into the string so that it is being read?
0
 

Author Comment

by:gigasausage
ID: 20108341
so, i just about have this nailed now... I went with a div instead of the popup window. The only problem now is that i have to use two buttons, one button to re-databind the dropdown control, and another button to hide the div. I suck at javascript, so if you could show me how to update the dropdown control and close the div in one function i would be done with this. thanks!
0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20108802
Ok, can you copy and paste the aspx page in the forum.  This will help me write the javascript.
0
 

Author Comment

by:gigasausage
ID: 20109024
'---- .aspx ----
<script language="JavaScript">
    function ShowPop(DivID) {
        document.getElementById(DivID).className == 'popperHid' ? document.getElementById(DivID).className = 'popperShow' : document.getElementById(DivID).className = 'popperHid';
        return false;
    }
 </script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                        <ContentTemplate>
                                                            <table>
                                                                <tr>
                                                                    <td>Contact Type:</td>
                                                                    <td>
                                                                        <a href="" onclick="return ShowPop('showContactTypes');" class="red7">Edit</a>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="2"><asp:DropDownList ID="intContactType" runat="server" DataSourceID="SqlDataSource1" DataTextField="txtType" DataValueField="ID" AppendDataBoundItems="True"></asp:DropDownList></td>
                                                                </tr>
                                                            </table>
                                                        </ContentTemplate>
                                                    </asp:UpdatePanel>


<div id="showContactTypes" class="popperHid">
      [content...]
      <input id="Button1" type="button" value="Close Window" onclick="return ShowPop('showContactTypes');" /><asp:Button ID="btnClose" runat="server" Text="Save Contact Types" OnClick="btnClose_Click" CausesValidation="False" />
</div>

'---- end .aspx ----

' --- .css file  ----
.popperHid {
    display:none;
}
.popperShow {
    position: absolute;
    z-index: 99;
    padding: 10px;
    border: 2px solid #708090;
    width: 320px;
    left: 46%;
    top: 360px;
    margin: 0 0 0 -200px;
    background: #ffffff;
    display:block;
    font-size: 90%;
}

0
 

Author Comment

by:gigasausage
ID: 20123454
The above is the pertinent sections from the application. If i were to paste the whole page it would be about 1000 lines of code. Will this do, or do you need something additional?
0
 
LVL 5

Expert Comment

by:KPMT-Technician
ID: 20123616
Sorry, been tied up at work.  
I will look at it today and this looks like it will be enough.
0
 

Author Comment

by:gigasausage
ID: 20174230
any luck with this by chance ?
0
 

Author Comment

by:gigasausage
ID: 21055803
yeah.. i have a problem with that.. lol.. at least give the points to KPMT-Technician for taking the time to try to answer, unless you want to give them back to me.
0
 

Author Comment

by:gigasausage
ID: 21164231
objections
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21189490
Forced accept.

Computer101
EE Admin
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question