6 Replies Latest reply on May 17, 2010 10:30 AM by jonboy0000

    asp.net form to post entries to email WITH calendar-date input

    jonboy0000 Level 1

      Hi all. I don't know if this belongs in the "app developer" forum, I'm new to asp.net...



      I have an asp.net form on one page that sends the entries to an email address. Heres the script:



      <%@ Page Language="VB" EnableSessionState="False" 
      EnableViewState="False" Trace="False" Debug="False"%>
      <%@ Import Namespace="System.Web.Mail" %> 
      <script language="VB" runat=server> 

      Sub Page_Load(Sender as Object, E as EventArgs) 
         If Page.IsPostBack Then
             lblResponse.Text = "Your email has been sent."
         End If
      End Sub 
      Sub btn_Click(sender as Object, e as System.EventArgs)
      If  Request.Form("Email") <> "" Then
         Dim objMail As New MailMessage()
         objMail.From = Request.Form("Email")
         objMail.To = "jonathan.sicurella@roswellpark.org"
         objMail.Subject = Request.Form("Subject")
         objMail.Body = Request.Form("Message") & Request.Form("Message")
         objMail.BodyFormat = MailFormat.Text
         SmtpMail.SmtpServer = "smtp.roswellpark.org"
         lblResponse.Text = "Please enter an email address."
      End If
      End Sub

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.0 Transitional//EN" >
      <html xmlns="http://www.w3.org/1999/xhtml">


      other stuff...




      ...other stuff...


      <asp:Label class="main" id="lblResponse" 

      <form method="post" name="form2" runat="server">

      email:<br />
      <input type="text" size="44" class="main" name="Email" value="">

      <br />

      first:<br />
      <input type="text" class="main" size="20" name="First" value="">

      <br />

      last:<br />
      <input type="text" class="main" size="20" name="Last" value="">

      <br />
      <br />

      <b>Dates:</b><br />
      <br />
      <br />
              <input name="text1" type="text" />
              <a href="javascript:calendar_window=window.open('/asp/calendar.aspx?formname=form2.text1','c alendar_window','width=154,height=188');calendar_window.focus()">Calendar</a>

      <br />

      <input type="Submit" id="btnSubmit" OnServerClick="btn_Click" value="Send" runat="server" />



      ... etc, etc...







      The first red text is the beginning of the form. The second red text is the code for a textbox, with a link next to it, opening a popup window with a calendar on it. I select the date on the calendar and its SUPPOSED to close the pop up, and add the date to the textbox. Simple.


      Problem is - the calendar only works when "runat='server'" is taken away from the form declaration "<form... runat="server">". The form only works (sends the email) when "runat='server'" is stated. Can't fix one without breaking the other somehow.


      The second file is called "calendar.aspx." - if you need it - what the popup window actually opens and where the asp scripting for the calendar is. Script is:


      <%@ Page Language="vb" %>

      <script runat="server">
          Private Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs)
            Dim strjscript as string = "<script language=""javascript"">"
            strjscript &= "window.opener." & _
                  Httpcontext.Current.Request.Querystring("formname") & ".value = '" & _
                  Calendar1.SelectedDate & "';window.close();"
            strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
            Literal1.Text = strjscript  'Set the literal control's text to the JScript code
          End Sub

          Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)
             If e.Day.Date = datetime.now().tostring("d") Then
             e.Cell.BackColor = System.Drawing.Color.LightGray
             End If
          End Sub

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
          <title>Choose a Date</title>
      <body leftmargin="0" topmargin="0">
          <form runat="server">
              <asp:Calendar id="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" OnDayRender="Calendar1_dayrender" showtitle="true" DayNameFormat="FirstTwoLetters" SelectionMode="Day" BackColor="#ffffff" FirstDayOfWeek="Monday" BorderColor="#000000" ForeColor="#00000" Height="60" Width="120">
                  <TitleStyle backcolor="#000080" forecolor="#ffffff" />
                  <NextPrevStyle backcolor="#000080" forecolor="#ffffff" />
                  <OtherMonthDayStyle forecolor="#c0c0c0" />
              <asp:Literal id="Literal1" runat="server"></asp:Literal>

      This is probably a simple fix. Like I said I'm new to asp.net, and html-self-taught. I went through a couple tutorials, and cut and pasted some scripts I found online. I got everything to work seperately, but when I put it together, couldn't. THANKS!