Results 1 to 5 of 5

Thread: update drop down as soon as hitting add button on another form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2004
    Posts
    169

    update drop down as soon as hitting add button on another form

    here is the scenario:
    I have drop down box on webform1.aspx and a link to bring up webform2.
    on webform2, there is "add" button and text box which could add a new entry , how can I after click add button on webform2, the drop down list on webform1 gets updated as well.

    so user doesn't need to hit refresh to see the changes

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: update drop down as soon as hitting add button on another form

    Assuming you open the second window using "window.open", you can reference client side controls on the original document by using window.opener (assuming I remember correctly).

    However, one notes that by modifying the control's content on the client side, one will invalidate the control's viewstate and one will not be able to access the list item contents on postback (e.g. dropDownList.Items); one will have to use the posted back values available in Request.Form.
    Last edited by axion_sa; Sep 2nd, 2005 at 01:05 PM.

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: update drop down as soon as hitting add button on another form

    This is all done using Javascript.
    You need a JS function in your WebForm1 page that will add values to a listbox
    And you need to add JS to the OnClick event of your add button, which calls the JS function on WebForm1 and passes the values you want adding.

    Or, have all the JS on the OnClick on the add button that adds the data to the webform1's controls. I prefer the 1st method myself, as it keeps all the code relating to controls in the same page.

    I don't know this code off the top of my head, but I can post it on Monday when I get to work.

    Woka

  4. #4
    Lively Member
    Join Date
    Aug 2004
    Posts
    94

    Re: update drop down as soon as hitting add button on another form

    That's what I'm looking for too !

    How did you (redshirtme) solved this ?

    Otherwise, could Wokawidget (or someone) else tell me please ?


    Thx !

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: update drop down as soon as hitting add button on another form

    OK...Say you have WebForm1 and WebForm2.
    WebForm2 is the "child" form, that is opened when some action on WebForm1 is done by the user.
    In Web form1 you need the following JS:
    Code:
    <SCRIPT language="javascript">
    	function OpenPopUp(SomeParam)
    	{
    		var sFeatures = ''
    				
    		sFeatures=''
    		sFeatures+='top=100,'
    		sFeatures+='left=200,'
    		sFeatures+='height=500px,'
    		sFeatures+='width=400px,'
    		sFeatures+='scrollbars=no,status=no,toolbar=no'
    		window.open('WebForm2.aspx?ParamName='+SomeParam,'My Popup',sFeatures)
    	}	
    			
    	function CallBackFunction(SomeData)
    	{
    		'random code here that makes webform1 update
    	}
    </SCRIPT>
    Then in Page load you do the following:
    VB Code:
    1. Me.btnDoSomething.Attributes.Add("onclick", "OpenPopupWindow(" & _SomeParam.ToString & ");return false;")
    This means that when clicking on the button it runs the JS that we added to WebForm1 and opens up the popup.

    Now...in WebForm2 page load:
    VB Code:
    1. Me.btnDoSomething.Attributes.Add("onclick", "Javascript:window.opener.CallBackFunction(" & _SomeParam.ToString & ");return false;")
    Now when you click this it calls the call back JS on the WebForm1.

    Anyways. gotta go to a meeting. Will post more tmrw.

    Woooof

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width