?
Solved

Submit form after clearing field

Posted on 2008-10-24
3
Medium Priority
?
1,419 Views
Last Modified: 2012-05-05
Hello,

I have a form that has a search field on it.  When a person clicks search, the form is submitted and I am using the FormParameter in a Gridview to filter the records based on their entry into the field.  The default parameter for the FormParameter is %, so if the field is left blank and the form is submitted, all records are shown.

I have a second button called View All and when the user clicks on that, I want the field value to clear out then submit the form.

It is not working.  The first time I click the view all button, the form is sumbitted and the field is cleared out, but the gridview is still filtered.  The second time I click the view all button, I get the results I want, the form is sumbitted with the blank textbox and all records are shown.

How can I do this with one click of the view all button?  I thought maybe I could have javascript clear out the field, then submit, but I couldn't get that to work....

.cs and .aspx code below.

Thanks,
Bonnie
*******************
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
 
public partial class Email_List : System.Web.UI.Page
{
    protected void SetCounts(object sender, EventArgs e)
    {
        string strConnection =
           "Data Source=SQLB21.webcontrolcenter.com;Integrated Security=false;Initial Catalog=webdata;User ID=martindale;Password=el3cTric!";
 
        SqlConnection myConn = new SqlConnection(strConnection);
 
        SqlCommand myCommand = new SqlCommand("sp_CountRows", myConn);
        myCommand.CommandType = CommandType.StoredProcedure;
 
        SqlParameter myParm = myCommand.Parameters.Add("@row_count", SqlDbType.Int);
        myParm.Direction = ParameterDirection.Output;
 
        myConn.Open();
 
        myCommand.ExecuteNonQuery();
 
        // Use this syntax to get the value from the OUT parameter
        int row_count = (int)myParm.Value;
 
        myConn.Close();
 
        rowcountLabel.Text = "Total Rows: " + row_count.ToString();
 
        int StartRecord = (GridView1.PageIndex * GridView1.PageSize) + 1;
        int EndRecord = (StartRecord - 1) + GridView1.Rows.Count;
        int CurrentPage = GridView1.PageIndex + 1;
 
        pageLabel.Text = "Displaying records " + StartRecord + " to " + EndRecord + " Page:" + CurrentPage;
    }
    protected void searchButton_Click(object sender, EventArgs e)
    {
        GridView1.DataBind();
 
    }
    protected void clearButton_Click(object sender, EventArgs e)
    {
        searchTextBox.Text = "";
        GridView1.DataBind();
 
 
    }
}
 
 
********************************
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Email_List.aspx.cs" Inherits="Email_List" Title="Email Address List" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<meta http-equiv="Content-Language" content="en-us" />
<meta name="GENERATOR" content="Microsoft FrontPage 6.0" />
<meta name="ProgId" content="FrontPage.Editor.Document" />
<meta name="description" content="Let Martindale quote on your electric motor maintenance or metal cutting needs today!	" />
<meta name="keywords" content="martindale electric, electrical test equipment, commutator, commstone, saw, saws, sanding, bur,
undercutter, vacuum, demagnitizer, brush seater" />
<meta name="revisit-after" content="15" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Let Martindale Quote on your Electric Motor Maintenance Tools Today!</title>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style2 {font-family: Arial, Helvetica, sans-serif}
.style3 {font-size: 10px}
-->
</style>
 
<script type="text/javascript">
 
// Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use
 
//Enter domain of site to search.
var domainroot="www.martindaleco.com"
 
function Gsitesearch(curobj){
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
 
</script>
 
</head>
<body leftmargin="0" topmargin="0">
 
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td bgcolor="#FF9933" align="center" width="15%"><img border="0"
    src="../images/spinningsaw2.gif" alt="Electric Motor Repair" width="60" height="59"></td>
    
    <td width="65%" bgcolor="#FF9933" align="center" >
    <a target="_self"
    href="http://www.martindaleco.com"><img src="../images/banner2.gif" border="0"
    alt="Electric Motor Maintenance-Martindale Products" width="219" height="52" style="margin:10px 0px 10px 0px;"></a><br />
      
    <ul id="nav" style="width:550px; margin:0px 0px 20px 0px;">
      <li id="lihome"><a href="../default.aspx">Home</a></li>
      <li id="liproducts"><a href="../productindex2.htm">Products</a></li>
      <li id="licontact"><a href="../contactus.htm">Contact Us</a></li>
      <li id="lirfq"><a href="../requestquote.aspx">Quotes</a></li>
      <li id="linew"><a href="../whatsnew.htm">What's New</a></li>
      <li id="liparts"><a href="../partssheets.htm">Parts Sheet/Instructions</a></li>
      <li id="liabout"><a href="../aboutus.htm">About Us</a></li>
      <li id="lilinks"><a href="../links.htm">Links/Shows</a></li>
	  <li id="li1"><a href="../clearance.htm">Clearance</a></li>
      </ul>    
    </td>
    <td width="20%" bgcolor="#FF9933" align="left" style="height: 129px">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td><div class="normal" onmouseover="this.className='highlight'" onmouseout="this.className='normal'" onclick="window.location.href('http://' + location.host + location.pathname + location.search)">English</div></td>
    <td><div class="normal" onmouseover="this.className='highlight'" onmouseout="this.className='normal'" onclick="window.location.href('http://translate.google.com/translate?u=http%3A%2F%2F' + location.host + location.pathname + location.search + '&sl=en&tl=es&hl=en&ie=UTF-8')">Española</div></td>
    <td><div class="normal" onmouseover="this.className='highlight'" onmouseout="this.className='normal'" onclick="window.location.href('http://translate.google.com/translate?u=http%3A%2F%2F' + location.host + location.pathname + location.search + '&sl=en&tl=fr&hl=en&ie=UTF-8')">Français</div></td>
    </tr></table>
    <form action="http://www.google.com/search" method="get" onsubmit="Gsitesearch(this)">
      <span class="style1"><span class="style3"><a href="mailto:sales@martindaleco.com?subject=Web Inquiry">
      <font color="#000000">sales@martindaleco.com</font></a><br />
        phone:&nbsp; 216-521-8567<br />
        fax:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 216-521-9476<br />
        Site Search:<br /></span></span>
      <input name="q" type="hidden" />
      <input style="width: 70px;padding: 1px 2px 0 2px;margin: 0;border: 1px solid #000;" name="qfront" type="text" size="5" /> <input
      style="font-size: 10px;color: #F93;background: #000;border: 2px solid #000;cursor: pointer;margin-bottom: 1px;" name="Submit" type="Submit" value="Search" /> 
      </form>
  
      </td>
  </tr> 
  
</table>
 
    <form id="form1" runat="server">
<div align="center"> 
<table width="500">
<tr>
<td width="15%">&nbsp;</td>
<td width="70%" valign="middle"> <h3 style="font-family:Tahoma;">
    <br />
    Martindale Email Marketing List</h3></td>
<td width="15%" style="font-size: x-small; font-family: Tahoma"><a href="CSV_List.aspx">view<br />
    Datawarehouse<br />
    list</a></td>
</tr>
</table>
 
        
        <asp:TextBox ID="searchTextBox" runat="server"></asp:TextBox>
    <asp:Button ID="searchButton" runat="server" Text="Search" OnClick="searchButton_Click" />
    <asp:Button ID="clearButton" runat="server" Text="View All" OnClick="clearButton_Click" /><br /><br />
    
    
    <asp:Label ID="rowcountLabel" runat="server" Text="" Font-Bold="True" Font-Names="tahoma" Font-Size="Small"
        Width="334px"></asp:Label><br />
    <asp:Label ID="pageLabel" runat="server" Text="" Font-Bold="True" Font-Names="tahoma" Font-Size="Small"
        Width="334px"></asp:Label><br /><br />
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
        BorderWidth="1px" CellPadding="3" DataKeyNames="db_key" DataSourceID="ObjectDataSource1"
        ForeColor="Black" GridLines="Vertical" PageSize="25"  OnDataBound="SetCounts">
        <FooterStyle BackColor="#CCCCCC" Font-Names="Tahoma" Font-Size="Small" />
        <Columns>
            <asp:TemplateField HeaderText="Edit" ShowHeader="False">
                <EditItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" CommandName="Update"
                     ImageUrl="~/images/disk.png" ToolTip="Save Changes" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Edit"
                        ImageUrl="~/images/pencil.png" ToolTip="Edit Email Addresses"  />
                </ItemTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Delete" ShowHeader="False">
                <EditItemTemplate>
                    <asp:ImageButton ID="ImageButton3" runat="server" CausesValidation="False"
                            CommandName="Cancel" ImageUrl="~/images/diskx.png" ToolTip="Discard Changes" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="False" CommandName="Delete"
                        ImageUrl="~/images/cancel.png"  ToolTip="Delete Email Address"  />
                </ItemTemplate>
            </asp:TemplateField>
          
            <asp:TemplateField HeaderText="Email Address" SortExpression="email_address">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("email_address") %>' Width="255px"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("email_address") %>' Width="255px"></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Date Added" SortExpression="date_added">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("date_added", "{0:d}") %>' Width="71px"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("date_added", "{0:d}") %>' Width="71px"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" Font-Names="tahoma" Font-Size="Small" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" Font-Names="Tahoma" Font-Size="Small" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
        <RowStyle Font-Names="Tahoma" Font-Size="Small" />
        <EditRowStyle Font-Names="Tahoma" Font-Size="Small" ForeColor="Black" BackColor="#FFFF80" />
    </asp:GridView>
    <br />
    <br />
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete" OldValuesParameterFormatString="original_{0}" SelectMethod="GetEmailbySearch"
        TypeName="DataTableAdapters.tbl_Email_BlastTableAdapter" UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="Original_db_key" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="email_address" Type="String" />
            <asp:Parameter Name="date_added" Type="DateTime" />
            <asp:Parameter Name="Original_db_key" Type="Int32" />
        </UpdateParameters>
        <SelectParameters>
            <asp:FormParameter DefaultValue="%" FormField="searchTextBox" Name="email" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    
 
 
 
    <table width="100%">
    <tr>
    <td bgcolor="black">
    
    <p align="center">
    <font face="Arial" size="1" color="#FF9933">
    <u><a target="_self" href="http://www.martindaleco.com">
    <font color="#FF9933"><span style="background-color: #000000">Home</span></font></a></u><span style="background-color: #000000"> |
    <a href="../MetalWorkingMicaSaws.htm"><font color="#FF9933">Metal Working Mica Saws</font></a> |
    <a href="../rotaryburs.htm"><font color="#FF9933">Rotary 
    Burs</font></a> | <a href="../Undercutters.htm"><font color="#FF9933">Undercutters</font></a> |
    <a href="../abrasives.htm"><font color="#FF9933">Abrasives</font></a> |
    <a href="../commutatorgrinders.htm"><font color="#FF9933">Commutator Grinders</font></a> |
    <a href="../Electricaltestequipment.htm"><font color="#FF9933">Electrical Test 
    Equipment</font></a> | <a href="../electricianshandtools.htm">
    <font color="#FF9933">Electrician's Hand Tools </font></a>| </span>
    <a href="../otherproducts.htm"><font color="#FF9933">
    <span style="background-color: #000000">Other Products</span></font></a></font>
    </p>
</td></tr></table>
</div>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:Bonnie_K
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 22795689
on page load add the following line
clearButton.Attributes.Add("onClick", "Empty (" + clearButton.ClientID + ")");

in javascript function Empty add the follwoing line

function setControlValue(var name)
{
      document.getElementById(name).value = "";
}

0
 

Author Comment

by:Bonnie_K
ID: 22811054
Sorry it took so long for me to test this.  I get the same behavior with this, I have to click the view all button twice...

Thanks
Bonnie
0
 

Author Comment

by:Bonnie_K
ID: 22811170
Never mind, got it working.  I ended up using the following:

    public void Page_Load(Object sender, EventArgs E)
    {
            clearButton.Attributes.Add("onClick", "Empty ();");
    }


function Empty()
{
document.form1.searchTextBox.value = "";
}

Thanks for your help,
Bonnie
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question