Results 1 to 10 of 10

Thread: Request.Form collection

  1. #1
    Join Date
    Mar 2004

    Arrow Request.Form collection

    Hello all,

    I have a problem with a such simple thing as to get values from the Request.Form collection.

    I created ASP.NET application using VS.NET and C# as a programming language. On the first webform I have <form id="test"> with the two textfields and one <asp:button>.

    Within the button event I have


    When I am trying to retrieve values from the "test" form in the "NameOfThePage.aspx" webform by using:

    string var="";
    var = Context.Request.Form.Get("textBox1").ToString();

    it gives me an error message in this line.

    The error message is:

    Object reference not set to an instance of an object

    Could anyone explain me what is going on here.

    Your help is very much appreciated.

  2. #2
    Join Date
    Nov 2002
    Auburn, AL
    The problem is you are mixing this with <asp: asp.net elements. Use one or the other, use all html forms with an action pointing to your script with the request stuff on it, or use all asp.net elements, leave out the action and jam all the scripts in the head section. With the asp.net elements you do not need to specify an action or anything like that, when the page is resent (which can be specified on many elements with autopostback and will happen by default with command buttons) the scripts at the top of your page will then execute, and those ids/names do not need ot be requested because the ids of asp.net elements are treated as variables thoughtout your page. You are thinking in terms of asp classic where you need to request the form attributes, but asp.net event aware controls keep you from having to do this and stream line you code a bit.

  3. #3
    Join Date
    Mar 2004

    Arrow Forms in asp.net

    Hi there,

    Thanks for you help, but the problem is that I havn't really got you. Could you please give me a very simple code example how to do this. Maybe create form with one textfield and button in one webform and show me how to get value from the textfield in another webform. Just bear in mind that i am using Visual Studio.NET so my html part and code behind are separated.
    Thanks in advance

    P.S. Your answer is very important for me because I am a very beginner in asp.net and currently I got involved in a real life project where without this knowledge I can't proceed.I already went through a couple of books and I canít find the right answer.
    Last edited by allagliner; 05-06-2004 at 06:47 PM.

  4. #4
    Join Date
    Nov 2002
    Auburn, AL
    Look, you have the asp.net elements, which start with a <asp: and then you have your standard html forms. Now, this asp.net elements output html form elements, but when using the asp.net elements, they are event aware. This means you can call a block of code based on the user clicking on the button. This can also be done with the html form elements in a way, but the key difference is that with the asp.net elements, you do not need to play with the form action, and you do not need to do a request.form. Plus even if you did, request.form will not work with a response.redirect, those form imputs are carried to the next page when the user clicks the button because the next page is the form action. So basically here is what you do, make all of your elements <asp: elements, then on the click of a command button call a sub within a sub that is at the top of you page or in a code behind and set some variables in the session, then if you need to redirect pass the variables over to the next page. But you can do all of your data base stuff right from the script up above, moving a bunch of crap to the next page would most likely be pointless. Do you own the books you have? You can't just scoure them for what you are looking for because what you are looking for cannot, and does not need to be done. You need to learn how to use asp.net, and that will mean either learning to work with a form action and html form elements, or the asp.net elements, or both, but not at the same time. You can use a server side text box and stuff like that, but you are going to have to specify a form action within a server side form and it could get really messy real fast. It probably will not work for you, but I am not going to say that is impossible because it could be.

  5. #5
    Join Date
    Nov 2003
    Derby, UK
    I don't want to step on your toes PeOfEo (because you obviously know a hell of a lot more about ASP.NET than I do), but I get the feeling that the miss-understanding is that the Form data from the 1st page will be transferred over as part of the Response.Redirect to the 2nd page.

    It's my understanding that the information does not get passed through to the 2nd, and that all Request.Form information will be empty.

    I apologise if I have totally missed the point of the question.
    I am not young enough to know everything - Oscar Wilde

  6. #6
    Join Date
    Nov 2002
    Auburn, AL
    If you use a form action, on a regular form, the data will be passed to the next page and you can use request.froms. If you use a server side form and asp.net elements, the data will be automatically passed by the server right back to the page the form is on, no second page what so ever. There would also be no need for request.forms.

  7. #7
    Join Date
    Nov 2003
    Derby, UK
    I totally agree with you - that is exactly how I understand it to work.

    But allagliner used Response.Redirect("NameOfThePage.aspx")
    and that - I think - is where the miss-understanding lies. It's my belief that the Server Side redirection (using Response.Redirect) will not pass any of the form values over.
    I am not young enough to know everything - Oscar Wilde

  8. #8
    Join Date
    Nov 2002
    Auburn, AL
    nope, not unless he redirects w/ a query string or sets a cookie or something. But its just that he is trying to do a request.forms while using a server side form. Its just uneccessary.

  9. #9
    Join Date
    Aug 2006

    Talking Answer

    Hi everyone i guess that the solution is:

    (in the button that send to the next page)

    Private Sub btnContinuar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinuar.Click
    Server.Transfer("NextPage.aspx", True)
    End Sub

    (in the page that receives the values [in this case is NextPage.aspx])

    Var1 = Page.Request.Form("campo1")
    Var2 = Page.Request.Form("campo2")

    Hope it helps...

  10. #10
    Join Date
    Aug 2006
    Lahore, Pakistan
    Why posting to other form? use the same from and get the values from the


    property it is better to implement the logic in the same form and If you really want to post to another page please read this article.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10818 seconds
  • Memory Usage 2,941KB
  • Queries Executed 13 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates