Showing posts with label whidbey. Show all posts
Showing posts with label whidbey. Show all posts

Thursday, March 29, 2012

Please Fix Form Post in Whidbey

I used to have forms like this that would post the information to the next website (listed in Action). This simple task has become onerous in VS.NET. Please please come up with a simple correction for this! Maybe a new control or something? I've seen some commercial controls attempt to use server transfer (not quite what I wanted). I've also tried doing it myself, but the next page will never display and it needs to because it has the result in HTML format! Come on...this was a 5 second deal in HTML and weeks in ASP.NET!!!!

<form method=post action="https://website">
<font size=+1>Special Order</font><br>
<input type=hidden name="PartNo" value="S-001">
<input type=hidden name="Item" value="Special Order">
Price: $<input type=text name="Price" value="0" size=10>
<input type=hidden name="Price" value="m-Price;10">
... and so on

</form>You can now in Whidbey add a PostTargetUrl attribute to the buttons control. When you press a button that has the PostTargetUrl attribute specified, the page will post the data to the specified target.

<asp:Button … PostTargetUrl="MyPage.aspx" …>
There are several ways to post to other urls in v1.* today:
(1) Use regular <form> tag, without any runat=server attribute or controls.
(2) Use javascript to change the server form's action attribute on the fly.
(3) MetaBuilders.com has a free custom server form with action enabled.
(4) My WilsonWebForm enables both action and multiple server forms.

Monday, March 26, 2012

PLEASE help - simple problem

The problem I am having is actually easier to explain if you look at my code, so I'll start there (note: this is coded in whidbey - but I thought this question would be more appropriate here than the 2.0 forum)

<cod>
Function GetValue(ByVal field As String, ByVal type As String) As String

Dim value As String = ""

If (type = "Text") Then
value = CType(MyFormView.FindControl("HomeWidthText"), TextBox).Text.ToString
'value = CType(MyFormView.FindControl(field), TextBox).Text.ToString
End If
...
Return value
End Function

Sub validateAllFields()
If (GetValue("HomeWidthText", "Text") = "") Then
...
End If
...
End Sub
</code
So, what's not working about that code you might ask? Well, absolutely nothing if you run the code as is. Now, replace the green with the red and you get the following error:
"Object reference not set to an instance of an object."

What? That doesn't make any sense at all to me as field is set to a string and is exactly that - "HomeWidthText". I just don't get it.

Aaroninstead of:
Function GetValue(ByVal field As String,

make field a control, in the function instead of a string
That would makes sense but that ignores the whole intention of that function...to reduce code!

You see, I didn't want to consistently have to write the following...


Dim homeWidth As String = GetValue(CType(MyForm.FindControl("HomeWidthText"), Control), "Text")

There are literally hundreds of these and I want to be able to do something like

Dim homeWidth As String = GetValue("HomeWidthText", "Text")

And, it should take the "Text" parameter and determine that it is dealing with a text field and do that appropriately.

Can this not be done in ASP.Net 2.0?

Aaron