470,590 Members | 2,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

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

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.


Nov 18 '05 #1
7 1558
not sure if this wold help, but you might want to add:
runat="server"
when creating the object

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
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.

Nov 18 '05 #2
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" <fi******@hotmail.com> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
not sure if this wold help, but you might want to add:
runat="server"
when creating the object

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
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.


Nov 18 '05 #3
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" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
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.

Nov 18 '05 #4
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" <th**************************@icysoft.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
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.


Nov 18 '05 #5
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" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <th**************************@icysoft.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
> 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.
>
>
>
>



Nov 18 '05 #6
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" <q.***@manyworlds.com> a écrit dans le message de
news:eT*************@TK2MSFTNGP10.phx.gbl...
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.

Nov 18 '05 #7
It WORKS! (I made a mistake before).

Thanks a lot!

Q.

"Vidar Petursson" <th**************************@icysoft.com> wrote in
message news:us**************@TK2MSFTNGP09.phx.gbl...
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" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <th**************************@icysoft.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <q.***@manyworlds.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
> 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.
>
>
>
>



Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lars Netzel | last post: by
1 post views Thread by Pieter Coucke | last post: by
reply views Thread by Maart_newbie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.