Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this textbox ...
C#
<asp:TextBox ID="TextBoxlabo" runat="server">
                 

then i want to pass whatever ill put in it, to an input like this one ..
&
C#
lt;input id="txt_p5" type="text" name="txt_p5" />


i ve done in the other way using get and creating a string var but in the case i desire didnt works, if someone could help ill apreciate it so much please .

this is my example to pass an input box to a label asp.net

class 1 call PrincipalAgregados

C#
public string Prueba1
        {
            get
            {
                String C3 = "";
                C3 = Request.Form["txt_p1"].ToString();
                
                return C3;
            }
        }

class 2

C#
if (!IsPostBack)
            
            {
                
                
                PrincipalAgregados pag = (PrincipalAgregados)Context.Handler;

    

               
                Label_p1.Text = pag.Prueba1;
                


            } 

in the other way i couldnt :(
Posted
Updated 12-Dec-14 5:19am
v2
Comments
ZurdoDev 12-Dec-14 11:45am    
You need runat=server to be able to access an object through C#.

What exactly is your question?
Anisuzzaman Sumon 12-Dec-14 23:18pm    
You are right!

Is your input field and TextBox in same page or different I guess both are in same page.If they are not in same page you can apply little trick according to this solution.
You need to add runat="server" in your input as well as add id to it simultaneously you have to add OnTextChanged event and AutoPostBack="true" to the property of your TextBox as it is run at server then you can copy using code behind code give below
Code in ASPX:
ASP
<form id="form1" runat="server">
<div>

<asp:textbox id="atxt" ontextchanged="atxt_TextChanged" autopostback="true" runat="server" ></asp:textbox>
</div>
<input id="aID" type="text" runat="server" name="ainput" />
</form>


Code behind in .cs:
C#
protected void atxt_TextChanged(object sender, EventArgs e)
     {
         aID.Value = atxt.Text;

     }
 
Share this answer
 
v2
Comments
Member 11209288 15-Dec-14 10:17am    
I understood a few things but as I said im new on this then i have a question o questions i might say, first of all, they are not in the same page thats why i put

PrincipalAgregados pag = (PrincipalAgregados)Context.Handler;

with a server.transfer. still works?

then people i know said to me that obviously a var in javascript is different that a asp.net the how do u call that input if u didnt create a string var for replace it, well idk when a ran my proyect before put this, it shows a instance error that i never found it xD O WELL i couldnt, but im gonna try ur solution thanks
As mentioned in the comments, you'll need to add runat="server" on any control you want to access in C#.
 
Share this answer
 

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



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