Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all
my web page has an optional contact that user can add input text for any contact like cellphone or email,when user click create contact button, it make a input box with attributes like unique id(for example "txtrelat1") or runat="server"(in client-side but web page has an input box with id="txtrelat0" by default) and when user click submit button ,calls "register" method in server-side by onserverclick event,
main question is,when i use form1.FindControl("txtrelat0"),it's find and i can convert it to HtmlInputText but when i want form1.FindControl("txtrelat1") it's not find and return null?
thank's all


What I have tried:

HtmlInputText intex = FindControl("txtrelat0") as HtmlInputText;
Posted
Updated 26-Mar-16 2:32am

1 solution

The runat tag is processed by .net when the page is generated, it has no meaning client-side and adding an element with a runat tag from javascript doesn't make that a server-side control, it simply creates an element with an attribute that is ignored.

What you have to do is ensure the input you create has a unique name (the id is irrelevant) and in your server code use Request.Form to read the value. So create boxes like

<input type="text" name="text1"/>
<input type="text" name="text2"/>


then in your server-code

C#
Request.Form["text1"];
Request.Form["text2"];
 
Share this answer
 
Comments
mohamadMahmodi 26-Mar-16 9:09am    
thank you
mohamadMahmodi 26-Mar-16 16:27pm    
it's worked and return content of value but do you have any suggestion to I set their CSS Style attribute?
F-ES Sitecore 27-Mar-16 7:19am    
It depends how you are creating them, if you're using jQuery

var txt = $("<input type='text'/>").attr("style", "border:red");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900