PDA

View Full Version : I'm I missing something here?


CanMike
05-10-2006, 04:07 AM
<%@ Page Language="VB" debug="true"%>
<script runat="server">
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub page_load()
if IsPostBack then
lblout.text = txtWord1.text

call insertLineBreak(lblout.text, _
NumberOptions.SelectedItem.Value, _
WidthOptions.SelectedItem.Value)

lblout.text += txtWord2.text <- Doesn't this concatenate the strings

call insertLineBreak(lblout.text, _
NumberOptions.SelectedItem.Value, _
WidthOptions.SelectedItem.Value)
end if
end sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

sub insertLineBreak(textIn as String, NumLines as byte, Width as short)
dim LineCoutner as byte
for LineCoutner=1 to NumLines
lblout.text += "<br /><hr width='" & Width & "' align='left'>"
next
end sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>

<html>
<head><title>SubRoutine with Parameters Example</title></head>
<body>
Enter two words and click on submit<br />
<form runat="server">
<asp:textbox id="txtWord1" runat="server" text="Default text 1"/>
<asp:textbox id="txtWord2" runat="server" text="Default text 2"/>

<asp:radiobuttonlist id="WidthOptions" runat="server">
<asp:listitem id="w100" value="100" runat="server" />
<asp:listitem id="w300" value="300" runat="server" />
<asp:listitem id="w600" value="600" runat="server" />
</asp:radiobuttonlist>

<asp:dropdownlist id="NumberOptions" runat="server">
<asp:listitem>1</asp:listitem>
<asp:listitem>2</asp:listitem>
<asp:listitem>3</asp:listitem>
</asp:dropdownlist>

<asp:button id="button1" runat="server" text="Button"></asp:button>
<br />
<br />
<asp:label id="lblout" runat="server" text="default output"></asp:label>

</form>
</body>
</html>

Notice this code. I'm teaching myself ASPX from 'Beginning ASP.NET 1.1 with VB.NET 2003" from Wrox publishing and this is one of their examples.

For this example lets assign the value to txtWord1 as blue, and txtWord2 as banana.

When you run this in your browser it displays each entered text on separate lines with line drawn underneath the texts. Fine. But shouldn't that line lblout.text += txtWord2 concatenate the string so that the next line of text displayed would be bluebanana. Yet when you run the code it's not.

What's up with that?

vinyl-junkie
05-10-2006, 05:27 AM
But shouldn't that line lblout.text += txtWord2 concatenate the string so that the next line of text displayed would be bluebanana.
Wrong. Read what the code is doing. It's taking the first textbox, concatenating that to:

<br /><hr width='" & Width & "' align='left'>"
with Width being whatever radio button was chosen. Then concatenating the second textbox to that whole thing, then concatenating another string:

<br /><hr width='" & Width & "' align='left'>"
to the final result. View the source for the rendered page, and you'll see that it's doing exactly what it's supposed to do, which is to put each text box value on a separate line.

handshakeit
05-10-2006, 06:58 AM
sub page_load()
if IsPostBack then
lblout.text = txtWord1.text

call insertLineBreak(lblout.text, _
NumberOptions.SelectedItem.Value, _
WidthOptions.SelectedItem.Value)

lblout.text += txtWord2.text <- Doesn't this concatenate the strings

call insertLineBreak(lblout.text, _
NumberOptions.SelectedItem.Value, _
WidthOptions.SelectedItem.Value)
end if
end sub


See what insertLineBreak does.................

CanMike
05-10-2006, 11:33 AM
Duh! I completely ingored insertLineBreak. Now I see it.

Thanks a lot. I'm a PL/SQL developers/Oracle DBA by trade and have been asked to work on the web site. I've got a lot to learn.

My guess is I'll be back with more questions.

Again, thanks for the quick response.