How can I get the value from the client-side created element object?

Discussion in 'ASP .Net' started by Quentin Huo, May 25, 2004.

  1. Quentin Huo

    Quentin Huo Guest

    Hi:

    I created a web-form user control. And in client-site, there is a link which
    will create a Input element object when it is clicked.

    <script language=javascript>

    .......
    var nameInput = document.createElement("input");
    nameInput.setAttribute("id", "authorname");
    ......

    </script>

    But when click "save" button" on this page, I can not get the value of the
    created element object in the user control by (in C#)

    .......
    string x=Request["authorname"];
    .......

    So how can I get the value from the client-side created element in a user
    control of ASP.NET?

    Thanks

    Q.
    Quentin Huo, May 25, 2004
    #1
    1. Advertising

  2. Quentin Huo

    Filip Guest

    not sure if this wold help, but you might want to add:
    runat="server"
    when creating the object

    "Quentin Huo" <> wrote in message
    news:...
    > Hi:
    >
    > I created a web-form user control. And in client-site, there is a link

    which
    > will create a Input element object when it is clicked.
    >
    > <script language=javascript>
    >
    > ......
    > var nameInput = document.createElement("input");
    > nameInput.setAttribute("id", "authorname");
    > .....
    >
    > </script>
    >
    > But when click "save" button" on this page, I can not get the value of

    the
    > created element object in the user control by (in C#)
    >
    > ......
    > string x=Request["authorname"];
    > ......
    >
    > So how can I get the value from the client-side created element in a user
    > control of ASP.NET?
    >
    > Thanks
    >
    > Q.
    >
    >
    >
    >
    Filip, May 25, 2004
    #2
    1. Advertising

  3. No, this won't help on the client side. "runat" is an instruction for
    ASP.NET. There is no ASP.NET on the client side.

    There are several way how to transmit values from client to server. You can
    use <input type=hidden> element, or you can add a parameter to the query
    string, not limited to these 2 only.

    Eliyahu

    "Filip" <> wrote in message
    news:...
    > not sure if this wold help, but you might want to add:
    > runat="server"
    > when creating the object
    >
    > "Quentin Huo" <> wrote in message
    > news:...
    > > Hi:
    > >
    > > I created a web-form user control. And in client-site, there is a link

    > which
    > > will create a Input element object when it is clicked.
    > >
    > > <script language=javascript>
    > >
    > > ......
    > > var nameInput = document.createElement("input");
    > > nameInput.setAttribute("id", "authorname");
    > > .....
    > >
    > > </script>
    > >
    > > But when click "save" button" on this page, I can not get the value of

    > the
    > > created element object in the user control by (in C#)
    > >
    > > ......
    > > string x=Request["authorname"];
    > > ......
    > >
    > > So how can I get the value from the client-side created element in a

    user
    > > control of ASP.NET?
    > >
    > > Thanks
    > >
    > > Q.
    > >
    > >
    > >
    > >

    >
    >
    Eliyahu Goldin, May 25, 2004
    #3
  4. Hi

    This should work

    Client
    var e = document.createElement("INPUT");
    e.name = "theNAME"; // Name of element
    document.forms["FORMNAME"].appendChild(e);

    Server
    string sRes = (Request.Form["theNAME"] != null ) ?
    Request.Form["theNAME"].ToString() : "";

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Scripting MVP
    http://www.microsoft.com/technet/scriptcenter
    ==============================
    "Quentin Huo" <> wrote in message
    news:...
    > Hi:
    >
    > I created a web-form user control. And in client-site, there is a link
    > which
    > will create a Input element object when it is clicked.
    >
    > <script language=javascript>
    >
    > ......
    > var nameInput = document.createElement("input");
    > nameInput.setAttribute("id", "authorname");
    > .....
    >
    > </script>
    >
    > But when click "save" button" on this page, I can not get the value of
    > the
    > created element object in the user control by (in C#)
    >
    > ......
    > string x=Request["authorname"];
    > ......
    >
    > So how can I get the value from the client-side created element in a user
    > control of ASP.NET?
    >
    > Thanks
    >
    > Q.
    >
    >
    >
    >
    Vidar Petursson, May 25, 2004
    #4
  5. Quentin Huo

    Quentin Huo Guest

    Hi:

    Unfortuately, it doesn't work. But anyway, thanks for you guys.

    So I am thinking another way to handle this: how can I create elements
    dynamically in server-side?

    I am trying to create a page for edit books' information. Some books have
    one author and some books have more than one authors. So, I want to give
    only one text box for the author name. And I will create a link saying "more
    authors". When a book has two authors, click the "more authors" link and a
    new text box will be created in the server-side.

    I know I should create a method in the code-behind to handle the click event
    for that link. But I want to know how to create an element ( such as input
    box) in the server-side?

    I tried to create a asp:label named "newAuthors" (ID) in the page, and I
    create the new text box as:

    .......

    newAuthors.Text = "<input runat=server id=newAuthors name=newAuthors >";

    .......

    but if I put a name in this box and post the page, the name that I input
    cannot be shown in the box anymore (I think it is not in the VIEWSTATE). So
    I think there should be another better way to create an element in ASP.NET.

    Any better way?

    Thank you very much!

    Q.




    "Vidar Petursson" <> wrote in
    message news:%...
    > Hi
    >
    > This should work
    >
    > Client
    > var e = document.createElement("INPUT");
    > e.name = "theNAME"; // Name of element
    > document.forms["FORMNAME"].appendChild(e);
    >
    > Server
    > string sRes = (Request.Form["theNAME"] != null ) ?
    > Request.Form["theNAME"].ToString() : "";
    >
    > --
    > Best Regards
    > Vidar Petursson
    > ==============================
    > Microsoft Scripting MVP
    > http://www.microsoft.com/technet/scriptcenter
    > ==============================
    > "Quentin Huo" <> wrote in message
    > news:...
    > > Hi:
    > >
    > > I created a web-form user control. And in client-site, there is a link
    > > which
    > > will create a Input element object when it is clicked.
    > >
    > > <script language=javascript>
    > >
    > > ......
    > > var nameInput = document.createElement("input");
    > > nameInput.setAttribute("id", "authorname");
    > > .....
    > >
    > > </script>
    > >
    > > But when click "save" button" on this page, I can not get the value of
    > > the
    > > created element object in the user control by (in C#)
    > >
    > > ......
    > > string x=Request["authorname"];
    > > ......
    > >
    > > So how can I get the value from the client-side created element in a

    user
    > > control of ASP.NET?
    > >
    > > Thanks
    > >
    > > Q.
    > >
    > >
    > >
    > >

    >
    >
    Quentin Huo, May 25, 2004
    #5
  6. Quentin Huo

    Patrice Guest

    Check :
    - you have a name attribute
    - it is inside the client side form tag
    - it is enabled (likely by default)

    Else it is not posted to the server

    Patrice

    "Quentin Huo" <> a écrit dans le message de
    news:...
    > Hi:
    >
    > I created a web-form user control. And in client-site, there is a link

    which
    > will create a Input element object when it is clicked.
    >
    > <script language=javascript>
    >
    > ......
    > var nameInput = document.createElement("input");
    > nameInput.setAttribute("id", "authorname");
    > .....
    >
    > </script>
    >
    > But when click "save" button" on this page, I can not get the value of

    the
    > created element object in the user control by (in C#)
    >
    > ......
    > string x=Request["authorname"];
    > ......
    >
    > So how can I get the value from the client-side created element in a user
    > control of ASP.NET?
    >
    > Thanks
    >
    > Q.
    >
    >
    >
    >
    Patrice, May 25, 2004
    #6
  7. Hi

    Hmmm just tested it here and it worked perfectly, no problem getting
    the data in input....

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Visual: Scripting MVP 2000-2004
    http://www.icysoft.com/
    http://www.deus-x.com/ Instant e-commerce
    http://www.microsoft.com/technet/scriptcenter/
    Playground: http://213.190.104.211/ ( IE 5.5+ only )

    No matter where you go there you are
    ==============================
    "Quentin Huo" <> wrote in message
    news:%...
    > Hi:
    >
    > Unfortuately, it doesn't work. But anyway, thanks for you guys.
    >
    > So I am thinking another way to handle this: how can I create elements
    > dynamically in server-side?
    >
    > I am trying to create a page for edit books' information. Some books have
    > one author and some books have more than one authors. So, I want to give
    > only one text box for the author name. And I will create a link saying
    > "more
    > authors". When a book has two authors, click the "more authors" link and a
    > new text box will be created in the server-side.
    >
    > I know I should create a method in the code-behind to handle the click
    > event
    > for that link. But I want to know how to create an element ( such as input
    > box) in the server-side?
    >
    > I tried to create a asp:label named "newAuthors" (ID) in the page, and I
    > create the new text box as:
    >
    > ......
    >
    > newAuthors.Text = "<input runat=server id=newAuthors name=newAuthors >";
    >
    > ......
    >
    > but if I put a name in this box and post the page, the name that I input
    > cannot be shown in the box anymore (I think it is not in the VIEWSTATE).
    > So
    > I think there should be another better way to create an element in
    > ASP.NET.
    >
    > Any better way?
    >
    > Thank you very much!
    >
    > Q.
    >
    >
    >
    >
    > "Vidar Petursson" <> wrote in
    > message news:%...
    >> Hi
    >>
    >> This should work
    >>
    >> Client
    >> var e = document.createElement("INPUT");
    >> e.name = "theNAME"; // Name of element
    >> document.forms["FORMNAME"].appendChild(e);
    >>
    >> Server
    >> string sRes = (Request.Form["theNAME"] != null ) ?
    >> Request.Form["theNAME"].ToString() : "";
    >>
    >> --
    >> Best Regards
    >> Vidar Petursson
    >> ==============================
    >> Microsoft Scripting MVP
    >> http://www.microsoft.com/technet/scriptcenter
    >> ==============================
    >> "Quentin Huo" <> wrote in message
    >> news:...
    >> > Hi:
    >> >
    >> > I created a web-form user control. And in client-site, there is a link
    >> > which
    >> > will create a Input element object when it is clicked.
    >> >
    >> > <script language=javascript>
    >> >
    >> > ......
    >> > var nameInput = document.createElement("input");
    >> > nameInput.setAttribute("id", "authorname");
    >> > .....
    >> >
    >> > </script>
    >> >
    >> > But when click "save" button" on this page, I can not get the value of
    >> > the
    >> > created element object in the user control by (in C#)
    >> >
    >> > ......
    >> > string x=Request["authorname"];
    >> > ......
    >> >
    >> > So how can I get the value from the client-side created element in a

    > user
    >> > control of ASP.NET?
    >> >
    >> > Thanks
    >> >
    >> > Q.
    >> >
    >> >
    >> >
    >> >

    >>
    >>

    >
    >
    Vidar Petursson, May 25, 2004
    #7
  8. Quentin Huo

    Quentin Huo Guest

    It WORKS! (I made a mistake before).

    Thanks a lot!

    Q.

    "Vidar Petursson" <> wrote in
    message news:...
    > Hi
    >
    > Hmmm just tested it here and it worked perfectly, no problem getting
    > the data in input....
    >
    > --
    > Best Regards
    > Vidar Petursson
    > ==============================
    > Microsoft Visual: Scripting MVP 2000-2004
    > http://www.icysoft.com/
    > http://www.deus-x.com/ Instant e-commerce
    > http://www.microsoft.com/technet/scriptcenter/
    > Playground: http://213.190.104.211/ ( IE 5.5+ only )
    >
    > No matter where you go there you are
    > ==============================
    > "Quentin Huo" <> wrote in message
    > news:%...
    > > Hi:
    > >
    > > Unfortuately, it doesn't work. But anyway, thanks for you guys.
    > >
    > > So I am thinking another way to handle this: how can I create elements
    > > dynamically in server-side?
    > >
    > > I am trying to create a page for edit books' information. Some books

    have
    > > one author and some books have more than one authors. So, I want to give
    > > only one text box for the author name. And I will create a link saying
    > > "more
    > > authors". When a book has two authors, click the "more authors" link and

    a
    > > new text box will be created in the server-side.
    > >
    > > I know I should create a method in the code-behind to handle the click
    > > event
    > > for that link. But I want to know how to create an element ( such as

    input
    > > box) in the server-side?
    > >
    > > I tried to create a asp:label named "newAuthors" (ID) in the page, and

    I
    > > create the new text box as:
    > >
    > > ......
    > >
    > > newAuthors.Text = "<input runat=server id=newAuthors name=newAuthors >";
    > >
    > > ......
    > >
    > > but if I put a name in this box and post the page, the name that I input
    > > cannot be shown in the box anymore (I think it is not in the VIEWSTATE).
    > > So
    > > I think there should be another better way to create an element in
    > > ASP.NET.
    > >
    > > Any better way?
    > >
    > > Thank you very much!
    > >
    > > Q.
    > >
    > >
    > >
    > >
    > > "Vidar Petursson" <> wrote in
    > > message news:%...
    > >> Hi
    > >>
    > >> This should work
    > >>
    > >> Client
    > >> var e = document.createElement("INPUT");
    > >> e.name = "theNAME"; // Name of element
    > >> document.forms["FORMNAME"].appendChild(e);
    > >>
    > >> Server
    > >> string sRes = (Request.Form["theNAME"] != null ) ?
    > >> Request.Form["theNAME"].ToString() : "";
    > >>
    > >> --
    > >> Best Regards
    > >> Vidar Petursson
    > >> ==============================
    > >> Microsoft Scripting MVP
    > >> http://www.microsoft.com/technet/scriptcenter
    > >> ==============================
    > >> "Quentin Huo" <> wrote in message
    > >> news:...
    > >> > Hi:
    > >> >
    > >> > I created a web-form user control. And in client-site, there is a

    link
    > >> > which
    > >> > will create a Input element object when it is clicked.
    > >> >
    > >> > <script language=javascript>
    > >> >
    > >> > ......
    > >> > var nameInput = document.createElement("input");
    > >> > nameInput.setAttribute("id", "authorname");
    > >> > .....
    > >> >
    > >> > </script>
    > >> >
    > >> > But when click "save" button" on this page, I can not get the value

    of
    > >> > the
    > >> > created element object in the user control by (in C#)
    > >> >
    > >> > ......
    > >> > string x=Request["authorname"];
    > >> > ......
    > >> >
    > >> > So how can I get the value from the client-side created element in a

    > > user
    > >> > control of ASP.NET?
    > >> >
    > >> > Thanks
    > >> >
    > >> > Q.
    > >> >
    > >> >
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Quentin Huo, May 25, 2004
    #8
    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. Shaul Feldman
    Replies:
    0
    Views:
    846
    Shaul Feldman
    Apr 16, 2004
  2. Boss302
    Replies:
    0
    Views:
    1,042
    Boss302
    Nov 21, 2006
  3. Bogdan
    Replies:
    2
    Views:
    650
    Bogdan
    Jun 9, 2008
  4. Jack
    Replies:
    4
    Views:
    188
    Phillip Windell
    Nov 26, 2003
  5. Jack
    Replies:
    3
    Views:
    208
Loading...

Share This Page