accessing Input text values from my code behind

G

Guest

I have 3 html input tex in my asp.net form. Two of them are calling
javascript client side to calculate the differnce of two dates and put the
result into the third input text. i haven't include runat=server in those
input texts. it works fine with me and i get the result in the third input
text. Now when i want to insert the 3 html input text values into my database
among other web controls ... i found out that i can't see them unlike web
controls such as textbox and dropdownlist ... it's suggesting me to declare
them first before i use them
so i did something like :
Dim txtFrom as HtmlInputText
Dim txtTo as HtmlInputText
and i tried but i am not getting the value even though i set to:

SqldataAdapter1.Insertcommand.Parameters(1).Value= txtFrom.Value

so what's the solution then? I tried to put runat="server" inside the
input text tag but them my function call is not working.
 
P

Programmer

Well
Try removing the declarations from the class
And after that go to the design HTML view and put Name , ID and Runat=server
and switch from Design To Preview And Back.
 
G

Guest

Here's the client side function i call :
function Calculate()
{

var toDate = makeDateObject(document.getElementById('txtTo').value);
var fromDate = makeDateObject(document.getElementById('txtFrom').value);
daysDifference = toDate.getTime()-fromDate.getTime()
daysDifference = Math.floor(daysDifference / (1000*60*60*24)) + 1;
document.getElementById('txtTotal').value = daysDifference;
if (document.getElementById('txtTo').value.length == 0 ||
document.getElementById('txtFrom').value.length == 0)
return;
}

</script>

and from here i call it:

<td>
From: <div>
<input id=txtFrom onchange="Calculate"><A
onclick="window.open('Calendar.aspx?textbox=txtFrom','cal','width=300,height=300,left=470,top=300')"
href="javascript:;"><IMG src="images/SmallCalendar.gif" border="0"></A>

</div> To: <div>
<input id=txtTo onchange="javascript:Calculate();"><A
onclick="window.open('Calendar.aspx?textbox=txtTo','cal','width=300,height=300,left=470,top=300')" href="javascript:;"><IMG
src="images/SmallCalendar.gif" border="0"> </A>

</div>
</td>

I am getting the result of the difference into this :

<td style="height: 34px">
<input id=txtTotal />
</td>

it's working properly... just the inserting thing .. any help will be
highly appreciated
 
B

Bruce Barker

you have two options:

1) fetch the postback value from the Request.Form collection

Request.Form["fieldname"]

2) place a runat=server on the textbox, and in the codebehind use the
attributes collection to add the client handler:

myTextBox.Attributes.Add("onclick","myClientFunction();");


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top