Solved

REQUEST.FORM QUESTION  ASP.NET

Posted on 2003-11-16
6
1,298 Views
Last Modified: 2013-11-25
Hi Im new in ASP.NET , I have problem validating with request.form syntax , it seem that if i send it to another page , all variable gone , I try to catch it using request.form.haskeys ... and return false


this is my code....

TEST.aspx....

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" Inherits="WebApplication1.test"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>test</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
            <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:TextBox id="txtname" style="Z-INDEX: 102; LEFT: 260px; POSITION: absolute; TOP: 65px" runat="server"></asp:TextBox>
                  <asp:TextBox id="txtaddress" style="Z-INDEX: 101; LEFT: 260px; POSITION: absolute; TOP: 92px" runat="server"></asp:TextBox>
                  <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 202px; POSITION: absolute; TOP: 73px" runat="server">Name</asp:Label>
                  <asp:Label id="Label2" style="Z-INDEX: 104; LEFT: 201px; POSITION: absolute; TOP: 97px" runat="server">Address</asp:Label>
                  <asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 369px; POSITION: absolute; TOP: 119px" runat="server" Text="Send"></asp:Button>
            </form>
      </body>
</HTML>


TEST.ASPX.VB   (code behind)
Public Class test
    Inherits System.Web.UI.Page
    Protected WithEvents txtaddress As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtname As System.Web.UI.WebControls.TextBox
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("result.aspx")
    End Sub
End Class


Another page for retrieving value........

RESULT.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="result.aspx.vb" Inherits="WebApplication1.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm2</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
            <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 145px; POSITION: absolute; TOP: 72px" runat="server">Your Name</asp:Label>
                  <asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 146px; POSITION: absolute; TOP: 98px" runat="server">Your Address</asp:Label>
                  <asp:Label id="lblname" style="Z-INDEX: 103; LEFT: 254px; POSITION: absolute; TOP: 72px" runat="server"></asp:Label>
                  <asp:Label id="lbladdress" style="Z-INDEX: 104; LEFT: 255px; POSITION: absolute; TOP: 95px" runat="server"></asp:Label>
            </form>
      </body>
</HTML>


Code Behind

Result.aspx.vb


Public Class WebForm2
    Inherits System.Web.UI.Page
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents lblname As System.Web.UI.WebControls.Label
    Protected WithEvents lbladdress As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblname.Text = Request.Form("txtname")
        lbladdress.Text = Request.Form("txtaddress")
    End Sub


End Class







0
Comment
Question by:teddysetiawan
  • 3
6 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 125 total points
ID: 9762786
teddysetiawan,

-In .NET environment, i'm afraid you can't do it in that way like in classical ASP. ASP.NET is support PostBack features. Why you want to do it in classical ASP method?
But, there still had some others way to get it work.

Work for request.QueryString() method
==============================================
You still can append the value inside the URL and retrieve it using request.queryString() just like what you can done in classical ASP.
eg:
To set the value
--------------------
Response.redirect('process.aspx?txtName=' & txtName.Text)

To get the value[others page]
---------------------------------------
<script runat="server">
Sub Page_Load
  Response.Write(Request.QueryString("txtName"))      
End Sub
</script>

However, you may not want to expose your data to others people inside your querystring and prefer request.Form() method.

Work for request.Form() method - use some javascript method inside asp.net page
===================================================================================

to set the value
------------------------------------
jscriptForm.aspx
-----------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="jscriptForm.aspx.vb" Inherits="JavascriptdotNetForm.jscriptForm"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>Post Data</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language="javascript">
<!--
function noPostBack(FormAction)
{
    if(document.layers) //support Netscape
    {
        document.layers['Content'].document.forms[0].__VIEWSTATE.name =
                                                           'NOVIEWSTATE';
        document.layers['Content'].document.forms[0].action = FormAction;
    }
    else //support DOM
    {
        document.forms[0].action = FormAction;
        document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
    }
}
-->
            </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <div id="Content" runat="server">
                  <form method="post" id="Form1" runat="server">
            <asp:TextBox id="txtName" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
            <asp:Button id="btnSubmit" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 104px" runat="server"
                  Text="Submit"></asp:Button>
                  </form>
            </div>
      </body>
</HTML>

jscriptForm.aspx.vb
=======================================================
Public Class jscriptForm
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Content As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents Submit As System.Web.UI.WebControls.Button
    Protected WithEvents txtName As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        btnSubmit.Attributes.Add("onclick", "noPostBack('process.aspx')")

    End Sub

End Class


To get the value
-----------------------
process.aspx
-------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="process.aspx.vb" Inherits="JavascriptdotNetForm.process"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>process</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:Label id="lblMsg" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 48px" runat="server"></asp:Label>
            </form>
      </body>
</HTML>

process.aspx.vb
----------------
Public Class process
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblMsg As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        lblMsg.Text = Request.Form("txtName") 'get value
    End Sub

End Class

-But, i'm still suggest you to use PostBack features that provided by .net itself. You can post back that same page and get the result before proceed to others page. That's will more easy and appropriate way to solve the problems.

Regards
x_com
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9785202
teddysetiawan,
why Gred B? I'd include explanations and sample coding. It's should be 'A' because i answer your answer completely.
Please Refer http://www.experts-exchange.com/help/closing.jsp#7

Regards
x_com
0
 
LVL 4

Author Comment

by:teddysetiawan
ID: 9793510
I'm sorry , I do not understand the grading policy here in EE ,
Thanks for the help x_com , but  how can I change the grade  ?
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9793726
teddysetiawan ,
It's ok. welcome to EE as well.
Admin will handle it. Next time, if you had questions about EE, you can always post the helps at CS area, admin will handle all the request from EE members :
http://oldlook.experts-exchange.com/Community_Support

Regards
x_com
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question