Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown value and StringBuilder

Status
Not open for further replies.

bobbybrown69

Programmer
Jun 11, 2003
15
US
Does anyone know how I would do this?

'** When a user selects an option from the dropdown box an onChange event modifies the value of the hidden input box below.
sb.Append("<input type=hidden name=descriptionName_" + vid + " value=""" & ds.Tables(0).Rows(i).Item("description").ToString() & """></td>")

'** I need to change "description" below to be what the user has chosen i.e. The value from the hidden input box descriptionName_ + vid
‘** instead of ds.Tables(0).Rows(i).Item("description").ToString()

This didn't work. document.forms[0].elements['descriptionName_" + vid + "'].value

sb.Append("<input type=hidden name=linerAd_" + vid + " value=""" + linerAd + ds.Tables(0).Rows(i).Item("description").ToString() + " " + signatureText + """>")
 
Your should use viewstate("descriptionName") and viewstate("userid") if you are only using these one the server.
If you need to access these on the client then stick with the hidden form elements.


This may simplify things:
<input type=hidden id=description runat=server />
<input type=hidden id=userid runat=server />

Select view Designer for a second and your two controls will be declared in the code behind file.
(protected withevents userid as System.Web.HTMLControls.HTMLHiddenInput)

You access the controls in codebehind as server controls.
description.value = "something"
userid.value = "john"

If you want to access them on the client then you should view the page source that is rendered in the browser and double check the ID attributes have not been amended (as they will if this is all in an ASCX file)
 
Thanks. I will try runat="server"

That will probably do the trick.
 
Here is the modified code. Why would I be receiving this error? Object variable or With block variable not set.

Dim descriptionName = descriptionName.value
sb.Append("<td><div id=divPreview" & vid & " style='background-color: #F2DA79; border: 1px solid black; padding: 3px; visibility: hidden; position: absolute; top:55px; right:2px;'></div>")
sb.Append("<select class=copy style='background-color: #FFFFFF' onchange=""document.forms[0].elements['descriptionName_" + vid + "'].value=this.options[this.selectedIndex].innerHTML; checkLinerLength('" & vid & "');"" name=DescriptionAdj_" & vid & ">")
If Not ds.Tables(0).Rows(i).Item("liner_descriptionadj") Is DBNull.Value Then
sb.Append("<option value=''>-- choose description --</option>" & Replace(descriptionAdjOptions, "value=""" & ds.Tables(0).Rows(i).Item("liner_descriptionadj") & """", "selected value=""" & ds.Tables(0).Rows(i).Item("liner_descriptionadj") & """") & "</select>")
Else
sb.Append("<option value=''>-- choose description --</option>" & descriptionAdjOptions & "</select>")
End If
sb.Append("<input type=hidden runat=server id=descriptionName name=descriptionName_" + vid + " value=""" & ds.Tables(0).Rows(i).Item("description").ToString() & """ /></td>")
sb.Append("<input type=hidden name=linerTextAndDescriptionAdj_" + vid + " value=''>")
sb.Append("<input type=hidden name=linerAd_" + vid + " value=""" + linerAd + descriptionName + " " + signatureText + """>")
 
You misunderstood the above code.
Write the hidden inputs directly in the ASPX page itself during design time not runtime.
You can't create server controls by adding the literal text
to the page during runtime. In other words you don't need the StringBuilder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top