<form> on masterpage and user controls
-
: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
-
: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
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; }
-
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; }
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!