views:

58

answers:

2

The form is defined as:

<%@ Page Language="C#" MasterPageFile="~/MasterPage1.Master" AutoEventWireup="true"
    CodeBehind="Search.aspx.cs" Inherits="Invoices.Search" Title="Search Page" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form id="LoginForm1" method="post" runat="server">

...

this is what i'm trying to do:

...

 <input id="date_input1" readOnly type="text" size="6" name="date_input1">
        <script language="JavaScript" type="text/javascript">
        <!--


  document.forms['LoginForm1'].date_input1.value = month + '/' + date  + '/' + year;

....

The problem is, nothing gets updated, the script just seems to hang and not do anything.

+1  A: 

The ID for LoginForm1 is not the client side id, because you have runat="server".

You could do, but it you change the 'date_input1' control to a server side control this would not work either.

document.forms[0].date_input1.value = month + '/' + date  + '/' + year;

To be honest, there are better ways to handle this kind of feature in ASP.NET

Dustin Laine
That worked.What would be the 'better way' of handling this in ASP.NET?I'm asking because I'm new to web programming, I'm much more comfortable with assembly language and C/C++.Thank you very much for the answer :)
Yuriy Y. Yermilov
Well using ASP.NET webforms handling this from server side and using the TextBox webcontrol you could handle this nicely. Without relying on Javascript. However, I would recommend checking out ASp.NET MVC as it is much more designed for client side development.
Dustin Laine
Oh I see. The thing is, what i've showed you is a very small snippet of what's going on. This is a piece of code that is part of a calendar done in JavaScript which is quite a bit of code.
Yuriy Y. Yermilov
A: 

Another way you could do it is use Jquery to select the element. No matter how crazy ASP.net makes the ID of the control, the original ID will always be the same in the end of the ID string.

Jquery can select elements based on many many things, and one of them is to check part of the ID for a match.

How your code would look.

$("[id$='_date_input1']").val("New Value");

Janko describes that way of doing it, in an article here:

http://www.jankoatwarpspeed.com/post/2009/01/08/Select-ASPNET-server-controls-easily-with-jQuery.aspx

Moulde