problem using hidden field in aspx webpage!

Discussion in 'ASP .Net' started by Jeff, Jul 24, 2009.

  1. Jeff

    Jeff Guest

    hi

    asp.net 3.5

    I'm trying to integrate a paypal button to my webpage. On my webpage I have
    a list of hidden fields which have parameters which will be sent back to
    PayPal when user clicks on the image:
    <input type="hidden" name="t3" value="M">
    <input type="hidden" name="sra" value="1">

    PROBLEM
    One of the hidden fields I need to set during runtime, This hidden field
    should contain username. PayPal require this hidden field to be named
    "custom", but during runtime I notice that my hidden field has a different
    name despite I named it "custom":
    The name I see in the html source is
    "ctl00$ContentPlaceHolder1$cuwNewUser$__CustomNav1$custom"

    In the markup I created this hidden field this way:
    <input type="hidden" name="custom" runat="server" id="custom" />

    In the code I reference the hidden field this way:
    HtmlInputHidden hidden =
    (HtmlInputHidden)TempStep.CustomNavigationTemplateContainer.FindControl("custom");
    (it happens inside a create user wizard)

    What am I doing wrong here?
    Jeff, Jul 24, 2009
    #1
    1. Advertising

  2. Jeff

    Leon Guest

    On Fri, 24 Jul 2009 10:47:19 +0200, "Jeff"
    <> wrote:

    >hi
    >
    >asp.net 3.5
    >
    >I'm trying to integrate a paypal button to my webpage. On my webpage I have
    >a list of hidden fields which have parameters which will be sent back to
    >PayPal when user clicks on the image:
    ><input type="hidden" name="t3" value="M">
    ><input type="hidden" name="sra" value="1">
    >
    >PROBLEM
    >One of the hidden fields I need to set during runtime, This hidden field
    >should contain username. PayPal require this hidden field to be named
    >"custom", but during runtime I notice that my hidden field has a different
    >name despite I named it "custom":
    >The name I see in the html source is
    >"ctl00$ContentPlaceHolder1$cuwNewUser$__CustomNav1$custom"
    >
    >In the markup I created this hidden field this way:
    ><input type="hidden" name="custom" runat="server" id="custom" />
    >
    >In the code I reference the hidden field this way:
    >HtmlInputHidden hidden =
    >(HtmlInputHidden)TempStep.CustomNavigationTemplateContainer.FindControl("custom");
    >(it happens inside a create user wizard)
    >
    >What am I doing wrong here?
    >


    The clientID for the server-side controls are being created (generated
    one might say) by the framework; these names can not be changed.
    What you could do is fumble around with JavaScript (although I
    personally wouldn't recommend it - due to browser versions and other
    problems).

    Workaround #1

    What you could do (as a workaround) is put your hidden fields inside a
    DataRepeater, bind a datatable (with just that one row) to the
    repeater and use something like this

    <input type="hidden" value='<%# Eval("CustomFieldName") %>'
    id="custom">

    (mark the usage of ' and " in the value)

    Workaround #2

    Create a panel surounding (or inside) your "POST" form (and don't set
    visible=false but set size to 1,1 or something) and add a
    literalcontrol to that control like

    {panel}.Control.Add(new LiteralControl("<input type....

    ..L.
    Leon, Jul 24, 2009
    #2
    1. Advertising

  3. Indeed with everything that Leon mentioned. Just one news, in ASP.NET 4.0,
    you will be able to set the ClientID property to whatever you wish.

    --
    Coskun Sunali
    Microsoft MVP - ASP.NET
    http://sunali.com
    http://propeople.dk

    "Leon" <> wrote in message
    news:...
    > On Fri, 24 Jul 2009 10:47:19 +0200, "Jeff"
    > <> wrote:
    >
    >>hi
    >>
    >>asp.net 3.5
    >>
    >>I'm trying to integrate a paypal button to my webpage. On my webpage I
    >>have
    >>a list of hidden fields which have parameters which will be sent back to
    >>PayPal when user clicks on the image:
    >><input type="hidden" name="t3" value="M">
    >><input type="hidden" name="sra" value="1">
    >>
    >>PROBLEM
    >>One of the hidden fields I need to set during runtime, This hidden field
    >>should contain username. PayPal require this hidden field to be named
    >>"custom", but during runtime I notice that my hidden field has a different
    >>name despite I named it "custom":
    >>The name I see in the html source is
    >>"ctl00$ContentPlaceHolder1$cuwNewUser$__CustomNav1$custom"
    >>
    >>In the markup I created this hidden field this way:
    >><input type="hidden" name="custom" runat="server" id="custom" />
    >>
    >>In the code I reference the hidden field this way:
    >>HtmlInputHidden hidden =
    >>(HtmlInputHidden)TempStep.CustomNavigationTemplateContainer.FindControl("custom");
    >>(it happens inside a create user wizard)
    >>
    >>What am I doing wrong here?
    >>

    >
    > The clientID for the server-side controls are being created (generated
    > one might say) by the framework; these names can not be changed.
    > What you could do is fumble around with JavaScript (although I
    > personally wouldn't recommend it - due to browser versions and other
    > problems).
    >
    > Workaround #1
    >
    > What you could do (as a workaround) is put your hidden fields inside a
    > DataRepeater, bind a datatable (with just that one row) to the
    > repeater and use something like this
    >
    > <input type="hidden" value='<%# Eval("CustomFieldName") %>'
    > id="custom">
    >
    > (mark the usage of ' and " in the value)
    >
    > Workaround #2
    >
    > Create a panel surounding (or inside) your "POST" form (and don't set
    > visible=false but set size to 1,1 or something) and add a
    > literalcontrol to that control like
    >
    > {panel}.Control.Add(new LiteralControl("<input type....
    >
    > .L.
    Coskun Sunali [MVP], Jul 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    3
    Views:
    8,149
    Alexey Smirnov
    Apr 13, 2010
  2. GavMc
    Replies:
    4
    Views:
    325
    Evertjan.
    Sep 22, 2005
  3. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    193
  4. Roy Adams
    Replies:
    3
    Views:
    266
    Dr John Stockton
    Dec 21, 2004
  5. RuthG
    Replies:
    5
    Views:
    597
    Michael J. Ryan
    Jun 18, 2009
Loading...

Share This Page