Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. <form> on masterpage and user controls

<form> on masterpage and user controls

Scheduled Pinned Locked Moved ASP.NET
winformsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moazzamahmed
    wrote on last edited by
    #1

    :omg: ok so I didnt think this would be such a big deal, but Im having trouble (errors etc.) accessing a

    on a masterpage, within a user control: 1. masterpage has

    2. then I have a aspx page that inherits from this master page, I have

    3. the user control's code-behind has if (!Page.IsPostBack) { RadioButtonList rblLocationHandle = (RadioButtonList) frmAddLocation.FindControl("rblAddLocation"); if (Request.Form["rblAddLocation"] == null) ... etc. but when I run the page, it says "frmAddLocation" is not valid in this context. So how do you access a form thats on the masterpage, in the user control? also, when my default.aspx page, which is part of ANOTHER masterpage, posts to the AddLocation.aspx page, Request.Form["rblAddLocation"] is always null! but Request.Form[4] isnt! how come? thing is, when I use [4], and I go to AddLocation page directly, meaning without a post, it bombs on [4]. now, I can catch it, and move on, but what the heck is going on? how do you use on master pages and user controls? thanks in advance! Moazzam

    G 1 Reply Last reply
    0
    • M moazzamahmed

      :omg: ok so I didnt think this would be such a big deal, but Im having trouble (errors etc.) accessing a

      on a masterpage, within a user control: 1. masterpage has

      2. then I have a aspx page that inherits from this master page, I have

      3. the user control's code-behind has if (!Page.IsPostBack) { RadioButtonList rblLocationHandle = (RadioButtonList) frmAddLocation.FindControl("rblAddLocation"); if (Request.Form["rblAddLocation"] == null) ... etc. but when I run the page, it says "frmAddLocation" is not valid in this context. So how do you access a form thats on the masterpage, in the user control? also, when my default.aspx page, which is part of ANOTHER masterpage, posts to the AddLocation.aspx page, Request.Form["rblAddLocation"] is always null! but Request.Form[4] isnt! how come? thing is, when I use [4], and I go to AddLocation page directly, meaning without a post, it bombs on [4]. now, I can catch it, and move on, but what the heck is going on? how do you use on master pages and user controls? thanks in advance! Moazzam

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use the "Ignore HTML" option when posting html, or it won't be readable. I have no idea why they chose to not encode the html code in the forum, it's a constant source of problems, but that's the way it works here. You can't access the control directly from within the user control, as the control is not part of the user control. If you want to access it, you need to do it through the reference to the page object, and cast it to the exact class of the page. This is the opposite of how a user control is supposed to work, though. It's purpose is that you should be able to reuse the control on more than one page, but that's not possible if the user control relies on being used on a specific page. When you use controls in a container, their client id changes, so you can't use Request.Form with the server id of the control. Look in the generated source code of the page to see what the client name of the control is.

      --- b { font-weight: normal; }

      M 1 Reply Last reply
      0
      • G Guffa

        Use the "Ignore HTML" option when posting html, or it won't be readable. I have no idea why they chose to not encode the html code in the forum, it's a constant source of problems, but that's the way it works here. You can't access the control directly from within the user control, as the control is not part of the user control. If you want to access it, you need to do it through the reference to the page object, and cast it to the exact class of the page. This is the opposite of how a user control is supposed to work, though. It's purpose is that you should be able to reuse the control on more than one page, but that's not possible if the user control relies on being used on a specific page. When you use controls in a container, their client id changes, so you can't use Request.Form with the server id of the control. Look in the generated source code of the page to see what the client name of the control is.

        --- b { font-weight: normal; }

        M Offline
        M Offline
        moazzamahmed
        wrote on last edited by
        #3

        thanks for the response. I tried to read the fields from the control but it wouldnt work, then all of a sudden it started to work. cause yeah I understand the user control shouldnt be dependent on anything else, or it breaks. I also found out, you dont use POST to transfer stuff anymore, just do postbacks, then transfer via response.redirect using querystring. did I get that right? thanks!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups