Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Hidden Form Field & ASP.NET Masterpage problem...

  • 08-10-2009 8:23am
    #1
    Closed Accounts Posts: 7,097 ✭✭✭


    Hi All,

    I'm using an aspx page to post some values in a hidden form field to a third party site. The landing page for the site is expecting certain values in these hidden form fields. When I pass the values to this page, there is an error.

    When I use a solution that doesn't have a masterpage, I don't get the error and all works fine but I'd like to use the masterpage if possible for completeness.

    What is happening is that the control literal (I think that's what it is called), for the content placeholder is being appended to the value in the hidden form field, so the string that is being passed, instead of what I want it to be which could be for example, "banana", ultimately gets passed as "cl003_contentplaceholder: banana", and as this landing page is expecting just "banana", an error is generated...

    Just wondering is there any way I can without going to any mad hassle, just remedy this little issue??? I've tried taking the <form> tag out of the masterpage which I thought would remedy the issue, but it seems that even if the form is being fully "handled" within the aspx page, because the aspx page is in a content placeholder, the value held in the form field gets appended and basically messed up! I've even tried putting the whole form inside the contentplaceholder on my aspx page but still my value in my form field is being messed up...


Comments

  • Registered Users, Registered Users 2 Posts: 128 ✭✭johnny_rambo


    Darragh29 wrote: »
    Hi All,

    I'm using an aspx page to post some values in a hidden form field to a third party site. The landing page for the site is expecting certain values in these hidden form fields. When I pass the values to this page, there is an error.

    When I use a solution that doesn't have a masterpage, I don't get the error and all works fine but I'd like to use the masterpage if possible for completeness.

    What is happening is that the control literal (I think that's what it is called), for the content placeholder is being appended to the value in the hidden form field, so the string that is being passed, instead of what I want it to be which could be for example, "banana", ultimately gets passed as "cl003_contentplaceholder: banana", and as this landing page is expecting just "banana", an error is generated...

    Just wondering is there any way I can without going to any mad hassle, just remedy this little issue??? I've tried taking the <form> tag out of the masterpage which I thought would remedy the issue, but it seems that even if the form is being fully "handled" within the aspx page, because the aspx page is in a content placeholder, the value held in the form field gets appended and basically messed up! I've even tried putting the whole form inside the contentplaceholder on my aspx page but still my value in my form field is being messed up...

    Hi Darragh,

    Have you tried just using a normal html input field (rather than a .Net control) and using a literal to populate the value of the hidden variable?

    Example:
    <input type="hidden" name="hiddenfieldName" id="hiddenfieldName" value='<asp:Literal ID="Literal_HiddenFieldValue" runat="server"></asp:Literal>' />
    


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Hi Darragh,

    Have you tried just using a normal html input field (rather than a .Net control) and using a literal to populate the value of the hidden variable?

    Example:
    <input type="hidden" name="hiddenfieldName" id="hiddenfieldName" value='<asp:Literal ID="Literal_HiddenFieldValue" runat="server"></asp:Literal>' />
    

    Hi JR, many thanks for that suggestion, I'll give it a shot and see if I have any luck with that...

    D


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Out of interest, how are you getting the ASP.net form to submit to a different site?


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    eoin wrote: »
    Out of interest, how are you getting the ASP.net form to submit to a different site?

    I'm using the PostBackURL property in the button properties. I did a bit of Googling on this and it seems that this can send back other stuff with the submit like Viewstate, but the funny thing is when I submit this form using an asp.net page that isn't using a masterpage, everything works grand but as soon as I try to use a masterpage, I get an error saying that the data is not correct.

    I've tried JR's idea there but no luck, I'm getting the same outcome.

    It isn't a show stopper, I just would rather use a masterpage for layout purposes and all of that...

    Another thing I've just noticed when I look at my page source is this...

    <input name="ctl00$ContentPlaceHolder2$ORDER_ID" type="hidden" id="ctl00_ContentPlaceHolder2_ORDER_ID" value="ORD453-91" />

    As you can see, the data in the form value field is fully intact and just as it should be, even though the ID string has been changed from what I set it up as on my aspx page which was: ORDER_ID, to ctl00_ContentPlaceHolder2_ORDER_ID, but my value field hasn't been changed in the same way so I don't really see why I'm having a problem here at all... :confused::confused::confused:

    In my codebehind page, I've used:

    ORDER_ID.Value = string.Format("ORD453-91");

    I just hardcoded in a dummy order number to get the thing working, it isn't actually this form field that is causing the issue by the way...


  • Registered Users, Registered Users 2 Posts: 128 ✭✭johnny_rambo


    I'm pretty sure my answer above will send the correct input field name in the request object to the third party page. Make sure you don't add runat="server" to the html input field as .Net will change the value in the 'name' and 'id' attributes. When implementing my solution, what name value gets sent to the third party page?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 128 ✭✭johnny_rambo


    Darragh29 wrote: »
    Another thing I've just noticed when I look at my page source is this...

    <input name="ctl00$ContentPlaceHolder2$ORDER_ID" type="hidden" id="ctl00_ContentPlaceHolder2_ORDER_ID" value="ORD453-91" />

    Is this what you see in the page source after implementing my solution? If so, you aren't implementing it correctly.

    In case I didn't communicate it properly......

    On the ASPX page
    <input type="hidden" name="ORDER_ID" id="ORDER_ID" value='<asp:Literal ID="Literal_HiddenField_OrderID" runat="server"></asp:Literal>' />
    

    On the Code behind page
    Literal_HiddenField_OrderID.Text="ORD453-91"
    

    There's no way you can get an ID of "ctl00_ContentPlaceHolder2_ORDER_ID" if you use the code above. No .Net controls should be used.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Hi JR,

    I've tried that fix in your last post...

    When I use:

    <input type="hidden" name="ORDER_ID" id="ORDER_ID" value='<asp:Literal ID="Literal_HiddenField_OrderID" runat="server"></asp:Literal>' />

    I get an error saying:

    The Name ORDER_ID does not exist in the current context...

    If I stick in a runat="server", changin' the above code to:

    <input type="hidden" name="ORDER_ID" id="ORDER_ID" runat="server" value='<asp:Literal ID="Literal_HiddenField_OrderID" runat="server"></asp:Literal>' />

    I get a different error:

    The Name Literal_HiddenField_ORDER_ID cannot be found in this context...

    Both errors are related to the codebehind page...

    I know you said not to use the runat="server" on the html, but I just stuck it in after the error popped up to see if it cleared it up...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Sorry JR, I forgot to change a bit of code in the codebehind to update the change, its working fine now, thanks so much for your help with this...


  • Registered Users, Registered Users 2 Posts: 128 ✭✭johnny_rambo


    Darragh29 wrote: »
    Sorry JR, I forgot to change a bit of code in the codebehind to update the change, its working fine now, thanks so much for your help with this...

    No problem


Advertisement