Form Posting and Master Pages

Last post 07-04-2007 1:51 AM by klaus_b. 10 replies.

Sort Posts:

  • Form Posting and Master Pages

    07-03-2007, 12:42 AM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    Hi All,

    I want to post a form that belongs within a master page. When I grab the data on the other end, using:

    string myString = Request.Form.Get("TextField");
    of course, no data comes back because the controls are renamed by the server by adding the prefix, "ctl00$ContentPlaceHolder$" (or something like that) and the client posts the form with the uniuqe names. How do I find find out what the prefix is (or is there a better way of doing what I am tyring to achieve)?
    Thanks in advance.
    Mat
  • Re: Form Posting and Master Pages

    07-03-2007, 1:32 AM
    • Contributor
      2,847 point Contributor
    • klaus_b
    • Member since 05-03-2006, 9:11 AM
    • Bavaria, Germany
    • Posts 566

    Hi Mat,

    matmc:
    string myString = Request.Form.Get(TextField);

    string myString = Request.Form.Get(TextField.ClientID)

    will maybe work.

     

    Servus,
    Klaus

    I haven't the faintest idea, but great many therefrom.
    klaus_b@.NET
  • Re: Form Posting and Master Pages

    07-03-2007, 2:24 AM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    Hi Klaus,

    klaus_b:

    Hi Mat,

    matmc:
    string myString = Request.Form.Get(TextField);

    string myString = Request.Form.Get(TextField.ClientID)

    will maybe work.

     

     

    I forgot the quotes around my parameter, and no, this didn't work. But thanks for the suggestion.

  • Re: Form Posting and Master Pages

    07-03-2007, 2:41 AM
    • Contributor
      2,847 point Contributor
    • klaus_b
    • Member since 05-03-2006, 9:11 AM
    • Bavaria, Germany
    • Posts 566

    Hi Mat,

    What kind of control is "TextField"? What will you GET from this control, his content? If so, use:

    string myString = Request.Get("TextField.ClientID").Text.ToString();

    For better understanding please explain more details.

     

    Servus,
    Klaus

    I haven't the faintest idea, but great many therefrom.
    klaus_b@.NET
  • Re: Form Posting and Master Pages

    07-03-2007, 2:59 AM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    TextField is a server-side textbox, i.e. 

    <asp:TextBox id="TextField" runat="server" />
     I am posting the form to another page. Is there any more information I can supply?
  • Re: Form Posting and Master Pages

    07-03-2007, 3:15 AM
    • Contributor
      2,847 point Contributor
    • klaus_b
    • Member since 05-03-2006, 9:11 AM
    • Bavaria, Germany
    • Posts 566

    Hi Mat,

    now is all clear. You need to use the previousPage tag. Here is an interested article for you.

    Hope this helps.

    Servus,
    Klaus

    I haven't the faintest idea, but great many therefrom.
    klaus_b@.NET
  • Re: Form Posting and Master Pages

    07-03-2007, 3:30 AM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    klaus_b:

    Here is an interested article for you.

    Thanks a million! It's my new homepage! (Joking)

  • Re: Form Posting and Master Pages

    07-03-2007, 4:07 AM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    Hmm... thanks heaps for your help, but I'm still a little confused...

    I had a read through the article, and I can't tell the difference between

    PreviousPage.FindControl("TextField"); //Returns the whole control
    and
    Request.Form.Get("TextField"); //Returns the value of the control

    While one returns an actual control, and the other returns a value in a control; in both instances I still need to use the whole unique name (ctl00$ContentPlaceHolder$TextField) as you can't directly access any elements on the sending form.

    Mat

  • Re: Form Posting and Master Pages

    07-03-2007, 4:33 AM
    • Contributor
      2,847 point Contributor
    • klaus_b
    • Member since 05-03-2006, 9:11 AM
    • Bavaria, Germany
    • Posts 566

    Mat,

    matmc:

    ... in both instances I still need to use the whole unique name (ctl00$ContentPlaceHolder$TextField) as you can't directly access any elements on the sending form.

    AFAIK you allways need the unique name of the control that you will access, if it was send to the client. For this reason asp.net give us the Property clientID, to access a control with his unique ID. If you will use the clientID property, you get the correct unique id for the control from .net automaticly. In case of PreviousPage.FindControl you have much more informations about this control, not only his value.

    Hope that makes it more clear.

     

     

    Servus,
    Klaus

    I haven't the faintest idea, but great many therefrom.
    klaus_b@.NET
  • Re: Form Posting and Master Pages

    07-03-2007, 10:16 PM
    • Member
      4 point Member
    • matmc
    • Member since 05-25-2007, 4:48 AM
    • Posts 12

    Ok, thats great. Now I guess my question is, how do you know what the server has assigned as the unique prefix (I don't want to have to manually code "ctl00$ContentPlaceHolder$TextField" every time, that would be poor programming)?

  • Re: Form Posting and Master Pages

    07-04-2007, 1:51 AM
    Answer
    • Contributor
      2,847 point Contributor
    • klaus_b
    • Member since 05-03-2006, 9:11 AM
    • Bavaria, Germany
    • Posts 566

    If you must use the prefix ctl00$ContentPlaceHolder you operate clientside. In my opinion let the "ServerControls" on the Server and the client "things" like JavaScript, AJAX and so on, on the Client. ClientSide X-postings are allways a problem from the point of security, because you can not validate what youre client get. Think on X-page scripting, script-injection. Ok, thats only in my mind.

    For this kind of problems my favorite is the PreviousPage. Here is a sample with the PreviousPage.FindControl() Method in C#

    1    if (Page.PreviousPage != null)
    2    {
    3        TextBox SourceBox = 
    4            (TextBox)Page.PreviousPage.FindControl("textField");
    5        if (SourceBox != null)
    6        {
    7            string myString = SourceBox.Text.ToString();
    8        }
    9    }
    
    and here you can read much more about Cross-Page Posting in ASP.NET Web Pages .
    Hope now is all clear for you.
    Servus,
    Klaus

    I haven't the faintest idea, but great many therefrom.
    klaus_b@.NET
Page 1 of 1 (11 items)