Showing posts with label fix. Show all posts
Showing posts with label fix. 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.

Wednesday, March 21, 2012

Please help me fix this code to make it work properly

default.asp code

<%

@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="True"></asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"/></Triggers></asp:UpdatePanel><asp:TimerID="Timer1"runat="server"Interval="2000"></asp:Timer></div><br/><asp:TextBoxID="TextBox1"runat="server"AutoPostBack="True">Input Test</asp:TextBox><asp:ButtonID="Button1"runat="server"Text="Button"/></form>

</

body>

</

html>

vb code

Partial

Class _DefaultInherits System.Web.UI.PageDim tempAsStringProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.LoadIf Page.IsPostBackThen

Label1.Text = temp

EndIfEndSubProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickDim iAsIntegerFor i = 0To 100

temp =

String.Format("{0} {1} {2}", TextBox1.Text, i,"<br />")NextEndSub

End

Class

The problem im getting is each time the page do a postback the temp's value is nothing. What do i need to look into to make it work?

Thanks!!

ASP.NET creates a new page object to service each request. This typically makes the application faster, more scalable and more reliable.

Therefore, you cannot maintain state in a field within a class (as you're attempting to do above).

You either need to store the data on the page (using ViewState, which generates a hidden field in the HTML) or in a Session object.

Both of these use simple indexing to put data in and get data out, as shown below:

ViewState("TempValue") = 10 ' put a value into the ViewState collection for this page

Dim i As Integer = CInt( ViewState("TempValue" ) ) ' get the value back out of the ViewState collection

Normally you should add code to make sure that the value you're reading is not nothing.

Be aware that ViewState data is present in the client HTML and can thus be read (and altered) unless you turn on ViewState protection. ViewState can really only be used on a single page.

Session data, on the other hand, is maintained on the Server and is thus more secure. Session can also be used across multiple pages.

You might want to check out some of the posts in the State Management forum (and in the ASP.NET documentation) for more details on ASP.NET state management technologies.


hi,

is it the case that you want to display value of temp in label if button is clicked,

simple after your for loop write this Label1.Text = temp in button click.

regards,

satish.


I'll go read on that topic some more .. Thanks


What i want to do is to have the temp value update each time from the loop

hi,

in your button click you've written temp = some value in for i=1 to 100, ok. so what will happen is at last it will contain values for i=100.

to persist value of temp you could store it in viewstate or a hidden field with runat=server. then in page load set temp = viewstate("temp")

then set lable.text = temp.

regards,

satish.