accessing Input text values from my code behind

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
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
 
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)
 
Back
Top