CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 5/31/2005 5:12:50 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 100 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
aesquive
Asp.Net User
AddHandler on Form Contrls DropDownList5/31/2005 5:12:50 PM

0/0

I have a addhandler that controls the events of a dropdownlist that is being built on the fly.  There could be one DDL ro multiple depending on what is returned from the DB.  When the user selects one of the three options in the DDL, then the results will create either a TxtBox or another DDL.

The issue that I am having is that if I have 3 DDL's and the user selects something from the first one, it hits the addhandler sub routine, and it creates either a txtbox or ddl. It reloads the page with the new control.  Here is where it gets tricky....if the user selects something with in the second DDL and it hits the addhandler again..only this time when it reloads the page it doesn't keep the first control that is built, it removes it and builds the new control. 

I'm puzzled on how I can keep each control that is built on the page? If you notice below, the user can change each one of the Function DDL's and in turn each one should build its own Value txtbox or ddl.  It does build the new control but I can't keep the previous control that was built.

Form Layout:

Lot: 722-7724 Rec. Qty: Function: NONE ALWAYS MULTIPLIER Value:
Bed-in-a-Bag Twin Sheet Set
A 2005
01/09/2005 - 08/27/2005
  Sku: 0349 Poetry
Lot: 722-7726 Rec. Qty: Function: NONE ALWAYS MULTIPLIER Value:
Bed-in-a-Bag Full Sheet Set
A 2005
01/09/2005 - 08/27/2005
  Sku: 0349 Poetry
Lot: 722-7728 Rec. Qty: Function: NONE ALWAYS MULTIPLIER Value


CODE (LoadPage where the DDL Function is being built) :
'Add DropDown List Items for ddlFunction
ddlFunction = New DropDownList
ddlFunction.AutoPostBack = True
ddlFunction.Items.Add(New ListItem(""))
ddlFunction.Items.Add(New ListItem("NONE"))
ddlFunction.Items.Add(New ListItem("ALWAYS"))
ddlFunction.Items.Add(New ListItem("MULTIPLIER"))

tr.Cells.Add(CreateDropDownListCell(ddlFunction, "ddlFunction" & strText, , 85, Css.Style.DefaultText))

'Create AddHandler for ddlFunction
AddHandler ddlFunction.SelectedIndexChanged, AddressOf ProcessDDLFunction

'Display Label name for TextBox
tr.Cells.Add(CreateTextCell("Value:", Css.Style.DefaultTextBold, , False, HorizontalAlign.Right))

'Display the Value field, either textbox or dropdown
strTRID = Right(tr.ID, 8)
strCurLotNum = CType(Session("strLotNum"), String)

If strTRID = CType(Session("strLotNum"), String) And CType(ddlFunction.SelectedIndex, String) <> CType(Session("strIndex"), String) Then
   If strText = strCurLotNum Then
      tr.Cells.Add(CType(Session("tcXCell"), TableCell))
   End If
End If

tblMain.Rows.Add(tr)

CODE (Sub Routine for AddHandler, where new control is being built):
'dllFunction = NONE, create TextBox(txtValue) default to ZERO
If CType(sender, DropDownList).SelectedIndex = 1 Then
   txtValue = New TextBox
   txtValue.AutoPostBack = False   
   tcXCell = CreateTextBoxCell(txtValue, "txtValue" & Right(CType(sender, DropDownList).ID, 8), "0", , 60, , Css.Style.DefaultText)
   Session("tcXCell") = tcXCell
ElseIf CType(sender, DropDownList).SelectedIndex = 2 Then

   'dllFunction = NONE, create TextBox(txtValue) default to blank
   txtValue = New TextBox
   txtValue.AutoPostBack = False
   tcXCell = CreateTextBoxCell(txtValue, "txtValue" & Right(CType(sender, DropDownList).ID, 8), , , 60, , Css.Style.DefaultText)
   Session("tcXCell") = tcXCell
ElseIf CType(sender, DropDownList).SelectedIndex = 3 Then
   'dllFunction = ALWAYS, create DropDown List with default values    
   ddlValue = New DropDownList
   ddlValue.AutoPostBack = False
   tcXCell = CreateDropDownListCell(ddlValue, "ddlValue" & Right(CType(sender, DropDownList).ID, 8), , 85, Css.Style.DefaultText)
   Session("tcXCell") = tcXCell   
End If

Session("strIndex") = CType(sender, DropDownList).SelectedIndex
strLotNum = Right(CType(sender, DropDownList).ID, 8)
Session("strLotNum") = strLotNum



 Thanks in advance for any help!

Adrian

subdigital
Asp.Net User
Re: AddHandler on Form Contrls DropDownList6/1/2005 3:03:31 AM

0/0

I didn't thoroughly examine your code, but I think I understand what is happening.

Basically the only controls that will remain on your page without you doing anything are the controls explicitly declared in the html.  Any other controls you wish to add must be created on every postback.  Instead of adding the controls directly to the page (or a control, whatever you're doing), add the new control to an arraylist and persist it in ViewState like this:

private const DYN_CTRLS as string = "DYN_CTRLS"
private _dynamicControls as ArrayList
public readonly property DynamicControls as ArrayList
    get
       if  _dynamicControls is nothing then
            if ViewState(DYN_CTRLS) is nothing then
                ViewState(DYN_CTRLS) = new ArrayList()
            end if
             _dynamicControls =  ViewState(DYN_CTRLS)
       end if
       return _dynamicControls
    end get
end property



Now, in your SelectedIndexChanged handler, you can add the new control to this list
Then, in the page load (on every postback) you need to render all of the controls in this list.

If you need to load differently depending on what type of control it is, then you could employ 2 lists, or rather check the type of the control in the list when rendering.

Hope this helps...


Ben Scheirman
http://www.flux88.com
aesquive
Asp.Net User
Re: AddHandler on Form Contrls DropDownList6/3/2005 7:27:04 PM

0/0

I have a new problem.

My addhandler works fine with the ArrayList.  Thing is that when the AddHandler get fired..the Page_Load gets processed then then my AddHandler function.  What I need for it to do is fire the Page_Load AFTER it finishs processing the code within the AddHandler function.  Any ideas?

ADDHANDLER FUNCTION:

Private Sub ProcessDDLFunction(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strLotNum As String
Dim aryNewCntrls As ArrayList
Dim i As Integer

'Current Lot Number
strLotNum = Right(CType(sender, DropDownList).ID, 8)

If arydynamicControls Is Nothing Then
   arydynamicControls = New ArrayList
Else
   'Retrieve DynamicControls ArrayList
   arydynamicControls = CType(Session("aryDynamicControls"), ArrayList)
End If

'dllFunction = NONE, create TextBox(txtValue) default to ZERO
If CType(sender, DropDownList).SelectedIndex = 1 Then
   arydynamicControls.Add(strLotNum & "to")
ElseIf CType(sender, DropDownList).SelectedIndex = 2 Then
   arydynamicControls.Add(strLotNum & "tb")
ElseIf CType(sender, DropDownList).SelectedIndex = 3 Then
   arydynamicControls.Add(strLotNum & "dl")
End If

Session("aryDynamicControls") = arydynamicControls
Session("blnDDLFlag") =
True

End Sub

3 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Visual Basic 2005 Programmer's Reference Authors: Rod Stephens, Pages: 1022, Published: 2005
Windows Forms Programming in Visual Basic .NET Authors: Chris Sells, Justin Gehtland, Pages: 680, Published: 2003
Visual Basic.NET Unleashed Authors: Paul Kimmel, Pages: 784, Published: 2002
Visual Basic 2005 with .NET 3.0 Programmer's Reference: Programmer's Reference Authors: Rod Stephens, Pages: 1200, Published: 2007
Professional Visual Studio 2005 Authors: Andrew Parsons, Nick Randolph, Pages: 869, Published: 2006
Programming .NET Windows Applications Authors: Jesse Liberty, Dan Hurwitz, Pages: 1228, Published: 2003
Visual Basic 2005: How to Program Authors: Harvey M. Deitel, Pages: 1513, Published: 2006
Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006
Developing .NET Custom Controls and Designers Using Visual Basic .NET Authors: James Henry, Pages: 600, Published: 2005
ASP.NET Data Web Controls Kick Start: Kick Start Authors: Scott Mitchell, Pages: 432, Published: 2003

Web:
Create Web Form Controls Dynamically - DevX.com Forums Create Web Form Controls Dynamically ASP.NET. ... NET's AddHandler method, How can we add 'DropDownList' control dynamically to an ASP. ...
AddHandler to Dropdownlist in ItemDataBound Doesnt work !! - .NET ASP AddHandler to Dropdownlist in ItemDataBound Doesnt work ! ... Why Values in Unbound Form Controls Don't Persist ...
EnableViewState = False DropDownList.SelectedValue not saving ... AddHandler ddl.Load, AddressOf RegionDropDownList_Load. Page.Form.Controls.Add( ddl). End Sub. Protected Sub CountryDropDownList_Load(ByVal ...
ToolStripDropDownItem.DropDown Property (System.Windows.Forms) DropDown = Me.contextMenuStrip1 AddHandler sb. ... and initializes three // ToolStripDropDownItem controls and adds them // to the form's ToolStrip control. ...
AddHandler SelectedIndexChanged Problem - .NET Forum What I want to be able to do is have one dropdownlist selection determine what is in ... Why Values in Unbound Form Controls Don't Persist ...
AddHandler doesn't seem to work. AddHandler ibnConfirm.Command, AddressOf ibnConfirm_Command ' Add to place holder collection plhConfirm.Controls.Add(ibnConfirm) ...
Adding dropdownlist to a datalist FindControl("ddl"), DropDownList) AddHandler ddl. ... recommend is that you use a hidden form field VB Helper: HowTo: Use dropdowns in a toolbar in VB .NET You select the text using a textual dropdown menu on the toolbar. ... In the Form's Load event handler, use AddHandler to set event handlers for each of the ...
Problem getting the Addhandler control to work : addhandler Dim ddl_new_exp_type, ddl_new_division, ddl_new_gl_code As DropDownList ...... I need a blank form that contains the controls that you see above (i.e. ...
ToolStripDropDownItem Class (System.Windows.Forms) Provides basic functionality for controls that display a ToolStripDropDown when a ToolStripDropDownButton ... DropDown = Me.contextMenuStrip1 AddHandler sb. ...




Search This Site:










imagebutton always triggering validation controls

redisplay page without redirect

executing user control code issue??

unable to populate dynamic drop down with viewstate

separate the message string, and have hyperlink on the words

validating multiple e-mail address - javascript & customvalidator

create an event for user control

not associated with trusted sql connection

add message box to a link button from server side code programatically using c# and asp 2.0

how to insert a dataset columns in html table

search engines

adding a panel to a tablerow

system.nullreferenceexception: object reference not set to an instance of an object (c#, asp.net)

need help to format navigateurl

importing data from an excel file

gridview formview querystring

analog of fileexplorer in asp.net

html server controls

dynamically change the wizard control

data binding - one way only??

open .hlp file in vb.net by passing parameter

design question

how to change backcolor of selected item in listbox ?

how to enable/disable validation controls in web user control and main page

caching the database to ram

user control error - object reference not set to an instance of an object.

text box does not accept multiple slash(\\\) but it accept one slash(\)

requiredfiledvalidator problem

regularexpressionvalidator

possible to clear all the text boxes on a web form with a single command?

  Privacy | Contact Us
All Times Are GMT