Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<table>
<tr>
<td>
<input type="text" id="txt" name="txt" />
</td>
</tr>
</table>



Hi,

I am typing some text in html text box.
Without giving runat ="server" how can I insert this into table using C#?

If I give runat ="server" I have to give in C# like

session["user"] = txt.value;


I want to know how to do it without using runat="server"
Posted
Updated 19-Oct-11 22:19pm
v5
Comments
Dalek Dave 20-Oct-11 4:20am    
Edited for Grammar and Readability.

Why you don't want to use runat="server"??

anyways here is the solution :-

You can use

var txtvalue = document.getElementById("txt").value;


but still you have to save this value (txtvalue) into any hidden field for further use in code behind.

Like:-

var txtvalue = document.getElementById("txt").value;

document.getElementById("<%=HiddenField1.ClientID %>").value = txtvalue;

Now you can use this hidden field value in code behind.

Like :-

session["user"] = HiddenField1.value;


--------------------------
You can also get value by this also :-

session["user"] = Request.Form["txt"];
 
Share this answer
 
v4
Hi,

you can do by using Jquery or basic xmlhttprequest.

JavaScript
  $.get("Default.aspx?action=getusername",{username:$("#txt").val()},function(data){
   $("#txt").text(data);
});


In code behind you've to write code

C#
//under pageload of default.aspx
if(request.Querystring["action"]!=null)
{
  response.clear();
response.write(Session["user"].tostring());
response.End();
}

without this that is not possible in my view

All the Best
 
Share this answer
 
v2
Comments
yerrojumeher 14-Oct-11 9:53am    
you sent me this code is working fine
but i want to display it textbox.not in div i tied that also its working fine.i want to store the text box value in a session.
<input type="text" id="resdiv" /> instead of div i took this

function addthis(tid, val1) {
if (tid.checked) {
document.getElementById("resdiv").innerText = parseInt(document.getElementById("resdiv").value) + parseInt(val1);
// document.getElementById("resdiv").style.visibility = 'hidden';

//document.getElementById("<%=hid.ClientID %>").value = document.getElementById("resdiv").innerText;
alert("hellop");
}
else {
document.getElementById("resdiv").innerText = parseInt(document.getElementById("resdiv").value) - parseInt(val1);
}
}
Muralikrishna8811 14-Oct-11 10:10am    
give runat="server" then store it in session
Muralikrishna8811 14-Oct-11 10:12am    
or use jquerypost method to post textbox value to server.
whenever the data in textbox changed.
As others have said, there is nothing wrong with Runat="server".
Perhaps if you gave us a reason why you do not wish to use it we could give more specific answers.
 
Share this answer
 
If you always want that value on the server side, and you want it to be updated (via a page refresh in ASP's 'special' style) when the user changes it, you should use runat=server. Values which are supposed to be submitted and mirrored in server code are exactly what runat=server is designed for.
 
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