Forum Moderators: open

Message Too Old, No Replies

.NET Variable Names

I REALLY need to use a FULLSTOP

         

Mr_Brutal

12:51 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



Hello,

Im pretty sure that you aren't allowed to use FULLSTOPS in variable names in .NET, but my problem is that I have to create a specific form with hidden fields that I wanted to populate from the code behind. The form I have to create contains fieldnames like "cust.email" which is why im having problems turning them into runat="server" fields which are available in my code behind.

1. Anyway can I use fullstops? (I know this is a NO but I cant find any web pages that state it this morning)

2. Can I use fullstops and then reference the fields like [cust.email] or "cust.email", neither of these work but is there something similair?

Cheers

TheNige

8:00 pm on Jan 18, 2005 (gmt 0)

10+ Year Member



Why not just change the id on the html side to "CustEmail" instead?

"." on the server side is how you reference an object's methods and properties.

"." also delimits names spaces...(system.web.ui.webcontrols)...so if you try to use them the compiler will look at it say it is incorrect...easy as that.

If you really need to use "." in your id names just don't use asp.net server controls...use standard HTML inputs and then get the values out using Request.form("Cust.Email")

Mr_Brutal

9:06 am on Jan 19, 2005 (gmt 0)

10+ Year Member



Thanks TheNige,

But the form is posted to an external script for processing that i can't modify. So the "."s need to stay in the form fields.

And I want to modfy the values from the .NET code so i can't use Request.Form.

I think im just gonna have to use Request.Write("")

Cheers anyway

duckhunter

2:19 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



You can setup a Request Form (old style) and populate the values with Properties set in the code behind.

<FORM>
<INPUT name="Field1" type="hidden" value="<%=Property1%>">
</FORM>

Then in the code behind:

Public Property Property1 as string
.....
End Property

Sub Page_Load
Me.Property1 = "My Value"
End Sub

TheNige

8:54 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



duckhunter's idea is good...bout the only way I can think of doing it.

Ocean10000

10:57 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is a Another way to Use Hidden Form Varables. This way Requires that the form be runat="server" though. The code to do this is the following
Page.RegisterHiddenField("fieldname","fieldvalue"); 
This will write the hidden fields. But on postback to get access to the data you have to use the
string result =this.Page.Request.Form["fieldname"];

For more info check out the info on MSDN
"Page.RegisterHiddenField"
[msdn.microsoft.com...]

"Request.Form"
[msdn.microsoft.com...]

Mr_Brutal

12:32 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Cheers all, it sounds like it would work, but in this situation im having to create a specifc HTML form INSIDE the .NET form.

I wanted to be able to set attributes like the action of the HTML form to be either the external server or our test server. Either way in making the form runat="server" it just submits to itself which isn't what i wanted.

I tried just making the form fields runat="server" as well but this also didn't work.

I have only about 9 fields so using Response.Write i just create the HTML field as the page loads and can change and set strings as i wish giving me a way to change the values as i wanted.

The form is from an external company so we can connect to their servers, its a poor way of doing but thats what they decided.

Cheers for your help!

duckhunter

3:55 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Ocean10000, thanks for that Page.RegisterHiddenField function. Just used it on something that was giving me a headache. Works like a champ!

Ocean10000

8:59 pm on Jan 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad I could help out duckhunter.

I use that little function alot with custom javascripts my webapplication needs to pass information back and forth between postbacks.