Image OnClick not firing but Button Event is - asp.net

I have the html & Code below.
When the user hits the page first I want them to be able to select their language by clicking on a Flag icon (before or after signing in). The event should fire and the language choice will be set. They then should be able to carry on logging into the site (if not already logged in) and performing whatever business they need.
My problem is, however, whenever I click on any flag icon the login and/or password box error message is displayed (if the textbox is empty) even thought the Button Click is not fired.
Can anyone please give me a pointer on where I am going wrong as I am obviously missing something (probably the obvious).
Many thanks in advance for any assistance offered
Regards
Iain
<form id="form1"
runat="server">
<div style="position: absolute; right : 0px; right : 5%;"> <!-- The Language Icons -->
<asp:ImageButton id = "imgbEnglish"
runat = "server"
onserverclick = "imgbEnglish_Click"
ImageUrl = "~/images/Union Jack.jpg"
Width = "20px"
ToolTip = "English"
visible = "true"/>
..........
..........
..............................................
There are 9 image icons of the same definition
..............................................
..........
..........
</div> <!-- The Language Icons -->
<table align="center">
<tr>
<td colspan="2" height="200px"></td>
</tr>
<tr>
<td>
</td>
<td>
<b>
<asp:Label ID = "lblLoginBoxHeader"
runat = "server"
text = "Sign In">
</asp:Label>
</b>
</td>
</tr>
<tr>
<td>
<asp:Label ID = "lblUsername"
runat = "server"
text = "User Name">
</asp:Label>
</td>
<td>
<asp:TextBox ID="txtUserName"
runat="server"/>
<asp:RequiredFieldValidator ID="rfvUser"
ErrorMessage="Please enter a Username"
ControlToValidate="txtUserName"
runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID = "lblPassword"
runat = "server"
text = "Password">
</asp:Label>
</td>
<td>
<asp:TextBox ID="txtPWD"
runat="server"
TextMode="Password"/>
<asp:RequiredFieldValidator ID="rfvPWD"
runat="server"
ControlToValidate="txtPWD"
ErrorMessage="Please enter a Password"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSubmit"
runat="server"
Text="Submit"
onclick="btnSubmit_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID = "lblSignedIn"
runat = "server"
text = "">
</asp:Label>
</td>
</tr>
</table>
// The code behind is
protected void Page_Load ( object sender, EventArgs e )
{
if (!IsPostBack)
{
getTheLanguage();
lblSignedIn.Text = lblSignedIn + "<br />" + "Is Postback";
}
else
{
lblSignedIn.Text = lblSignedIn + "<br />" + "Is Postback";
}
}
protected void imgbEnglish_Click ( object sender, ImageClickEventArgs e )
{
Session["Language"] = "English";
lblCurrentLanguage.Text = "English";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(odbcString);
OleDbCommand cmd = new OleDbCommand();
string sqlString = "SELECT UPPER(VENCODE), UPPER(PASSWORD), COMPANY, QUALSITE, VENDSITE, CUSTSITE " +
"FROM QUALITY.USERLIST " +
"WHERE VENCODE = '" + txtUserName.Text.ToUpper() + "' AND " +
"PASSWORD = '" + txtPWD.Text.ToUpper() + "' " +
"ORDER BY VENCODE";
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlString;
try
{
OleDbDataReader dsSite = cmd.ExecuteReader();
if (dsSite.HasRows)
{
lblSignedIn.Text = lblSignedIn + "<br />" + "Signed In";
}
else
{
lblSignedIn.Text = lblSignedIn + "<br />" + "Sign In Failed";
}
}
catch
{
}
con.Close();
}

Set
CausesValidation="false"
...
<asp:ImageButton id = "imgbEnglish"
runat = "server"
onserverclick = "imgbEnglish_Click"
ImageUrl = "~/images/Union Jack.jpg"
Width = "20px"
CausesValidation="false"
ToolTip = "English"
visible = "true"/>

Related

ASP.NET Edit a Field without reloading the whole Listview

I have a Listview and a dropdownlist:
<asp:ListView ID="lv_ClassTeacher" runat="server" vertical-align="top" OnSelectedIndexChanged="lv_ClassTeacher_SelectedIndexChanged" OnSelectedIndexChanging="lv_ClassTeacher_SelectedIndexChanging" DataKeyNames ="ClassID" OnPagePropertiesChanged="lv_ClassTeacher_PagePropertiesChanged" OnPagePropertiesChanging="lv_ClassTeacher_PagePropertiesChanging" OnItemDataBound="lv_ClassTeacher_ItemDataBound" OnItemCommand="lv_ClassTeacher_ItemCommand">
<LayoutTemplate>
<table border="1">
<tr runat="server">
<th runat="server"></th>
<th runat="server">Class</th>
<th runat="server">Teacher</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Button ID="cmd_View" runat="server" CommandName="Select" Text="View" Height="21px" /></td>
<td><div runat="server" id="area"><asp:Label ID="Label1" runat="server" Text='<%#Eval("Class") %>' /></div></td>
<td><asp:Label ID="Label2" runat="server" Text='<%#Eval("Teacher") %>' /></td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:DropDownList ID="cb_SwitchTeacher" runat="server" AutoPostBack = "true" OnSelectedIndexChanged="cb_SwitchTeacher_SelectedIndexChanged">
Part of code behind:
conn.Open();
using (MySqlCommand sqlCommand = conn.CreateCommand())
{
sqlCommand.CommandText = "SELECT * FROM tblClassTeacher";
using (MySqlDataAdapter sda = new MySqlDataAdapter(sqlCommand))
{
DataTable dt = new DataTable();
sda.Fill(dt);
lv_ClassTeacher.DataSource = dt;
lv_ClassTeacher.DataBind();
}
}
protected void cb_SwitchTeacher_SelectedIndexChanged(object sender, EventArgs e)
{
string TeacherName= cb_SwitchLabel.Text;
using (MySqlCommand sqlCommand = conn.CreateCommand())
{
sqlCommand.CommandText = "UPDATE tblClassTeacher SET Teacher=" + TeacherName + " WHERE ClassID=" + lv_ClassTeacher.SelectedDataKey.Value.ToString();
sqlCommand.ExecuteNonQuery();
//What can I do to update the listview without reloading the whole table?
}
}
}
On Pressing the "cmd_View", the Class field will be highlighted. When user switch to another Teacher on the dropdownlist, I will update the database.
But I want to update the listview as well without reloading the whole table.
Can I do that? Thank you.

Controls on page are not displaying respective values based on drop down selection

I have a User Registration page through which new users can be registered.
As seen in the ASPX page below, i have a User Name drop down. On selection of any value in this dropdown, the details of that user are to be displayed in the respective controls. This is happening only for the User Name text box.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div>
<table>
<tr>
<td class="style2">
<asp:Label ID="lbl_UserName" runat="server" Text="User Name: "
ForeColor="Black" CssClass="LabelStyles"></asp:Label>
</td>
<td class="style3">
<asp:DropDownList ID="ddl_UserName" runat="server"
onselectedindexchanged="UserName_Changed" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbl_tbUserName" runat="server" ForeColor="Black" Text="User Name: " CssClass="LabelStyles"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="tb_UserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbl_Password" runat="server" Text="Password: " ForeColor="Black" CssClass="LabelStyles"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="tb_Password" runat="server" TextMode="Password"
ForeColor="Black"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbl_cnfrmPassword" runat="server" ForeColor="Black" Text="Confirm Password: " CssClass="LabelStyles"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="tb_cnfrmPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbl_Admin" runat="server" Text="Admin: " ForeColor="Black" CssClass="LabelStyles"></asp:Label>
</td>
<td class="style3">
<asp:RadioButtonList ID="YesNo_RadioButtonList" runat="server" Height="22px"
RepeatDirection="Horizontal" Width="51px" ForeColor="Black">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0">No</asp:ListItem>
</asp:RadioButtonList>
</td>
Code behind for populating drop down
protected void Populate_ddlUserName()
{
dsRetrieveUserDetails = objLoginData.RetrieveUser();
dtUser.Columns.Add("UserID");
dtUser.Columns.Add("UserName");
dtUser.Rows.Add("", "Select User");
dtUser.Rows.Add("Add New", "Add New");
int count = dsRetrieveUserDetails.Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
{
dtUser.Rows.Add(dsRetrieveUserDetails.Tables[0].Rows[i]["UserID"].ToString() + "#" +
dsRetrieveUserDetails.Tables[0].Rows[i]["Password"].ToString() + "#" + dsRetrieveUserDetails.Tables[0].Rows[i]["Admin"].ToString(), dsRetrieveUserDetails.Tables[0].Rows[i]["UserName"].ToString());
}
ddl_UserName.DataSource = dtUser;
ddl_UserName.DataValueField = "UserID";
ddl_UserName.DataTextField = "UserName";
ddl_UserName.DataBind();
}
Code behind for selected index changed
protected void UserName_Changed(object sender, EventArgs e)
{
dsRetrieveUserDetails = objLoginData.RetrieveUser();
if (ddl_UserName.SelectedItem.Text == "Add New")
{
//Displaying hidden controls
lbl_tbUserName.Visible = true;
tb_UserName.Visible = true;
//Hiding unnecessary controls
btn_delNo.Visible = false;
btn_delYes.Visible = false;
lbl_DeleteMsg.Visible = false;
//Enabling&Disabling controls
btn_Reset.Enabled = true;
btn_Register.Enabled = true;
btnDelete.Enabled = false;
//Setting Values
tb_UserName.Text = "";
tb_Password.Text = "";
tb_cnfrmPassword.Text = "";
YesNo_RadioButtonList.ClearSelection();
}
else if (ddl_UserName.SelectedItem.Text == "Select User")
{
//Setting values
tb_UserName.Text = "";
tb_Password.Text = "";
tb_cnfrmPassword.Text = "";
YesNo_RadioButtonList.ClearSelection();
//Disabling controls
btn_Register.Enabled = false;
btn_Reset.Enabled = false;
btnDelete.Enabled = false;
//Hiding unnecessary controls
lbl_tbUserName.Visible = false;
tb_UserName.Visible = false;
lbl_DeleteMsg.Visible = false;
btn_delNo.Visible = false;
btn_delYes.Visible = false;
}
else
{
//Displaying some hidden controls
lbl_tbUserName.Visible = true;
tb_UserName.Visible = true;
//Setting values
tb_UserName.Text = ddl_UserName.SelectedItem.Text;
//Enabling&Disabling controls
btn_Register.Enabled = true;
btn_Reset.Enabled = true;
btnDelete.Enabled = true;
//Hiding unnecessary controls
lbl_DeleteMsg.Visible = false;
btn_delYes.Visible = false;
btn_delNo.Visible = false;
string[] values = ddl_UserName.SelectedValue.Split('#');
tb_Password.Text = values[1];
tb_cnfrmPassword.Text = values[1];
YesNo_RadioButtonList.SelectedIndex = YesNo_RadioButtonList.Items.IndexOf(YesNo_RadioButtonList.Items.FindByValue(values[2]));
}
}
Some additional info..
I've debugged using breakpoints and found that Password and Confirm Password are holding the correct text but the data does not get displayed in their respective text boxes. Where have i goofed up?

NavigateUrl in ASP.Net

I am new to ASP.NET. I am having problem with NavigateUrl.
<td align="right" valign="middle">
<p id="posCstmr">
<asp:HyperLink ID="hlnkContact" CssClass="addbtn-cmplist" runat="server" NavigateUrl='<%# "Actions/Contact.aspx?ContactID=" + Eval("ContactID") + "&CompanyID=" + Eval("CompanyID") %>' Text="View"></asp:HyperLink>
</p>
</td>
When I click to view following hlnkContact, it redirects to the following link with specified values which is OK.
[http://localhost:1426/Actions/Contact.aspx?ContactID=78724&CompanyID=92971]
But I want to store these values in session variables on Page_load event of Contact.aspx.
if (!Page.IsPostBack)
{
Session["ContactID"] = String.IsNullOrEmpty(Request.QueryString["ContactID"].ToString()) ? String.Empty : Session["ContactID"];
}
But I cant store the Session variable on Page_Load because NavigateUrl show the values after loading of this page.
Please Help me.
Same type of question was answered HERE, you can tweak like below:
[Assuming that the td is inside any databound container, else Eval wouldn't work]
Change your markup to this:
<td align="right" valign="middle">
<p id="posCstmr">
<asp:LinkButton ID="LinkButton1" CssClass="addbtn-cmplist" runat="server"
Text="View" CommandName="Link" CommandArgument='<%#Eval("ContactID") + ";" + Eval("CompanyID") %>'
OnClick="ButtonLink_Click" />
</p>
</td>
Code:
protected void ButtonLink_Click(object sender, System.EventArgs e)
{
LinkButton lb = (LinkButton)sender;
string[] arguments = lb.CommandArgument.Split(';');
string ContactID = arguments[0];
string CompanyID = arguments[1];
//Save in session
Session["ContactID"] = ContactID ;
Session["CompanyID"] = CompanyID ;
//Redirect
Response.Redirect(string.Format("Actions/Contact.aspx?ContactID={0}&CompanyID={1}", ContactID, CompanyID));
}

ASP.NET VB Page_Load Only Once or Alternative

I'm a little stuck on what to do! I have a special form that allows my customers to request a quote for a specific product (defined by PID in url) The form is loaded inside a modal dialogue and within that a Iframe. The Iframe's src value is set from the onclick event of ahref on the product pages eg;
<div id='basic-modal'><p><br /><br />CLICK ME</p></div>
<div id="basic-modal-content">
<iframe id="ifr" width="850px" height="600px" frameborder="0" scrolling="no"></iframe>
The form that I am loading does a SQL insert when Page_Load is fired. Also it is within
If Page.IsPostBack = False Then
For some strange reason the page is doing it twice when the page loads and another time when the page is closed.. I need the SQL insert on the first page load as the returned values are used by my form. Can anyone suggest a good way of making the code within Page_Load only fire up once?
Many thanks!
UPDATE, Full Code:
aspx page
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Public_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 runat="server">
<link href="../quoteFront.css" rel="stylesheet" type="text/css" />
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
height: 26px;
}
.style5
{
width: 299px;
}
.style6
{
width: 174px;
}
.style7
{
height: 26px;
width: 174px;
}
.style8
{
width: 291px;
}
.style9
{
height: 26px;
width: 189px;
}
.style10
{
}
.style11
{
width: 189px;
}
.style12
{
width: 191px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" CombineScripts="false" >
</cc1:ToolkitScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate>
<asp:Panel ID="Panel2" runat="server">
<table class="style1">
<tr>
<td class="style12">
First name</td>
<td class="style5">
<asp:TextBox ID="txtFirstName" runat="server" Width="300px"
AutoCompleteType="FirstName"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtFirstName" ErrorMessage="* Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style12">
Last name</td>
<td class="style5">
<asp:TextBox ID="txtLastName" runat="server" Width="300px"
AutoCompleteType="LastName"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtLastName" ErrorMessage="* Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style12">
Company name</td>
<td class="style5">
<asp:TextBox ID="txtCompanyName" runat="server" Width="300px"
AutoCompleteType="Company"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style12">
Email address</td>
<td class="style5">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="300px" AutoCompleteType="Email"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtEmailAddress" ErrorMessage="* Required"
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmailAddress" ErrorMessage=" * Invalid email address"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style12">
Phone number</td>
<td class="style5">
<asp:TextBox ID="txtPhoneNumber" runat="server" Width="300px" AutoCompleteType="BusinessPhone"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtPhoneNumber" ErrorMessage="* Required"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div>
<table class="style1">
<tr>
<td class="style11">
Quantity required</td>
<td class="style6">
<asp:TextBox ID="txtQuantity1" runat="server" AutoPostBack="True"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="ftbe" runat="server" FilterType="Numbers"
TargetControlID="txtQuantity1" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtQuantity1"
ErrorMessage="* Please enter quantity required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style11">
<asp:Label ID="lblDesigninfo" runat="server" Text="Printing info"></asp:Label>
</td>
<td class="style6">
<asp:DropDownList ID="drpDesignInfo1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="PrintInfoDesc"
DataValueField="ID" AppendDataBoundItems="True">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:quotingSystemConnectionString %>"
SelectCommand="SELECT [ID], [PrintInfoDesc] FROM [PrintInfo]">
</asp:SqlDataSource>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="drpDesignInfo1" ErrorMessage="* Please select"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style11">
<asp:Label ID="lblColoursSideOne1" runat="server"
Text="Colour options first side" Visible="True"></asp:Label>
</td>
<td class="style6">
<asp:DropDownList ID="drpColoursSideOne1" runat="server" Visible="True"
AutoPostBack="True">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
<asp:Label ID="lblColoursSideTwo1" runat="server"
Text="Colour options second side" Visible="false"></asp:Label>
</td>
<td class="style7">
<asp:DropDownList ID="drpColoursSideTwo1" runat="server" Visible="false">
</asp:DropDownList>
</td>
<td class="style2">
</td>
</tr>
</table>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtQuantity1" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="drpDesignInfo1"
EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="drpColoursSideOne1"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<div style="text-align: center">Please fill in the above fields before uploading
artwork.
<br />
When the upload is complete you will get the option to upload additional
artwork.
<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
CompleteBackColor="Lime" ErrorBackColor="Red"
OnClientUploadComplete="UploadComplete" OnClientUploadError="uploadError"
OnClientUploadStarted="StartUpload"
onuploadedcomplete="AsyncFileUpload1_UploadedComplete" ThrobberID="Throbber"
UploaderStyle="Modern" UploadingBackColor="#66CCFF" Width="100%"
ClientIDMode="Inherit" />
<asp:Label ID="Throbber" runat="server" Style="display: none">
<img src="../Images/indicator.gif" align="absmiddle" alt="loading" />
</asp:Label><asp:Label ID="lblStatus" runat="server"></asp:Label>
<br />
<div style="max-height:70px; overflow : auto; ">
<asp:Label ID="lblUploadList" runat="server" ForeColor="#006600"
Font-Size="Smaller"></asp:Label>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<table class="style1">
<tr>
<td class="style10">
Any aditional info<asp:TextBox ID="txtComments" runat="server" Height="111px"
TextMode="MultiLine" Width="100%"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style8">
<asp:Button ID="Button1" runat="server" Text="Send Request" Width="100%"
Height="45px" Font-Bold="False" />
</td>
</tr>
</table>
</asp:Panel>
<br />
<asp:Panel ID="Panel1" runat="server" Visible="False">
Thank you for requesting a quote. A member of our sales team will be in touch
shortly.<br />
<br />
<asp:Button ID="btnRequestAnother" runat="server"
Text="Request another quote for this product" CausesValidation="False"
Height="45px" Width="100%"/>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript" language="javascript">
function uploadError(sender, args) {
document.getElementById("lblStatus").innerHTML = "Failed to upload " + args.get_fileName() + ". Please try again. If problem persistes please email sales#thecleverbaggers.co.uk";
document.getElementById("Button1").innerHTML = 'Send Request';
}
function StartUpload(sender, args) {
document.getElementById("lblStatus").innerHTML = 'Uploading Started. Depending on your connection speed this can take a very long time. Please wait....';
document.getElementById("Button1").innerHTML = 'Uploading Started. Please Wait....';
}
function UploadComplete(sender, args) {
var filename = args.get_fileName();
var contentType = args.get_contentType();
var text = "Upload Complete, Press Select File to upload more. " //"Size of " + filename + " is " + args.get_length() + " bytes";
if (contentType.length > 0) {
text //+= " and content type is '" + contentType + "'.";
}
document.getElementById("lblStatus").innerHTML = text;
document.getElementById("lblUploadList").innerHTML = document.getElementById("lblUploadList").innerHTML + "<br />" + filename + " Uploaded Successfully";
document.getElementById("Button1").innerHTML = 'Send Request';
}
</script>
</form>
</body>
VB CODE:
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Partial Class Public_Default
Inherits System.Web.UI.Page
Dim ArtworkID As Integer
Dim customerIDDecrypt As String
Public QuoteID As Integer
Dim UploadedFileList As String
Dim productID As String
'Shared IsFirstTime As Boolean = False
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
productID = Request.QueryString("PID")
customerIDDecrypt = "0"
'If Not Page.IsPostBack AndAlso Not IsFirstTime Then
If Not Page.IsPostBack Then
Try
Dim sql As String = "INSERT INTO [Quote] (Status, CreationDate, CreationTime, CustomerID, ProductID, IP)" & _
"VALUES (#Status, #CreationDate, #CreationTime, #CustomerID, #ProductID, #IP) SELECT SCOPE_IDENTITY()"
Using cn As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionString")), _
cmd As New SqlCommand(sql, cn)
cmd.Parameters.Add("#Status", SqlDbType.NVarChar).Value = 1
cmd.Parameters.Add("#CreationDate", SqlDbType.Date).Value = Date.UtcNow.ToLocalTime
cmd.Parameters.Add("#CreationTime", SqlDbType.Time).Value = Date.UtcNow.ToLocalTime.TimeOfDay
cmd.Parameters.Add("#CustomerID", SqlDbType.Int).Value = customerIDDecrypt
cmd.Parameters.Add("#ProductID", SqlDbType.Int).Value = productID
cmd.Parameters.Add("#IP", SqlDbType.NVarChar).Value = CStr(Request.UserHostAddress())
cn.Open()
'//grab the ID of this insert.
QuoteID = Integer.Parse(cmd.ExecuteScalar().ToString())
cn.Close()
'IsFirstTime = True
End Using
Catch ex As Exception
'// do something with this error!
Response.Write(ex.Message)
End Try
End If
End Sub
Protected Sub txtQuantity1_TextChanged(sender As Object, e As System.EventArgs) Handles txtQuantity1.TextChanged
'//populate colours dependant on quantity
If txtQuantity1.Text > "" Then
If txtQuantity1.Text < "100" Then
'side one
drpColoursSideOne1.Items.Clear()
'drpColoursSideOne1.Enabled = True
drpColoursSideOne1.Items.Add(New ListItem("One colour", "1"))
drpColoursSideOne1.Items.Add(New ListItem("More than one colour", "full"))
drpColoursSideOne1.Items.Add(New ListItem("I don't know!", "help"))
drpColoursSideOne1.Visible = True
'side two
drpColoursSideTwo1.Items.Clear()
'drpColoursSideTwo1.Enabled = True
drpColoursSideTwo1.Items.Add(New ListItem("One colour", "1"))
drpColoursSideTwo1.Items.Add(New ListItem("More than one colour", "full"))
drpColoursSideTwo1.Items.Add(New ListItem("I don't know!", "help"))
drpColoursSideTwo1.Items.Add(New ListItem("na", "na"))
Else
'side one
drpColoursSideOne1.Items.Clear()
'drpColoursSideOne1.Enabled = True
drpColoursSideOne1.Items.Add(New ListItem("One colour", "1"))
drpColoursSideOne1.Items.Add(New ListItem("Two colours", "2"))
drpColoursSideOne1.Items.Add(New ListItem("Three colours", "3"))
drpColoursSideOne1.Items.Add(New ListItem("Four colours", "4"))
drpColoursSideOne1.Items.Add(New ListItem("Five colours", "5"))
drpColoursSideOne1.Items.Add(New ListItem("Full colour (eg, photo)", "full"))
drpColoursSideOne1.Items.Add(New ListItem("I don't know!", "help"))
'side two
drpColoursSideTwo1.Items.Clear()
'drpColoursSideTwo1.Enabled = True
drpColoursSideTwo1.Items.Add(New ListItem("One colour", "1"))
drpColoursSideTwo1.Items.Add(New ListItem("Two colours", "2"))
drpColoursSideTwo1.Items.Add(New ListItem("Three colours", "3"))
drpColoursSideTwo1.Items.Add(New ListItem("Four colours", "4"))
drpColoursSideTwo1.Items.Add(New ListItem("Five colours", "5"))
drpColoursSideTwo1.Items.Add(New ListItem("Full colour (eg, photo)", "full"))
drpColoursSideTwo1.Items.Add(New ListItem("I don't know!", "help"))
drpColoursSideTwo1.Items.Add(New ListItem("na", "na"))
End If
Else
'nothing
End If
End Sub
Protected Sub drpDesignInfo1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpDesignInfo1.SelectedIndexChanged
If drpDesignInfo1.SelectedValue = "1" And txtQuantity1.Text > "0" Then
lblColoursSideTwo1.Visible = False
lblColoursSideOne1.Visible = True
drpColoursSideOne1.Visible = True
drpColoursSideOne1.Enabled = True
drpColoursSideTwo1.Visible = False
drpColoursSideTwo1.Enabled = False
drpColoursSideTwo1.SelectedValue = "na"
' drpColoursSideTwo1.Items.Remove(New ListItem("Same as the first side", "same"))
ElseIf drpDesignInfo1.SelectedValue = "3" And txtQuantity1.Text > "0" Then
lblColoursSideOne1.Visible = True
drpColoursSideOne1.Visible = True
drpColoursSideOne1.Enabled = True
lblColoursSideTwo1.Visible = True
drpColoursSideTwo1.Visible = True
drpColoursSideTwo1.Enabled = True
' drpColoursSideTwo1.Items.Remove(New ListItem("Same as the first side", "same"))
ElseIf drpDesignInfo1.SelectedValue = "2" And txtQuantity1.Text > "0" Then
lblColoursSideOne1.Visible = True
drpColoursSideOne1.Visible = True
drpColoursSideOne1.Enabled = True
lblColoursSideTwo1.Visible = True
drpColoursSideTwo1.Visible = True
drpColoursSideTwo1.Enabled = False
' Dim tmpCount2 = drpColoursSideTwo1.Items.Count
' If tmpCount2 = 7 Or tmpCount2 = 3 Then
'drpColoursSideTwo1.Items.Add(New ListItem("Same as the first side", "same"))
'End If
drpColoursSideTwo1.SelectedValue = drpColoursSideOne1.SelectedValue
End If
End Sub
Protected Sub AsyncFileUpload1_UploadedComplete(sender As Object, e As AjaxControlToolkit.AsyncFileUploadEventArgs)
System.Threading.Thread.Sleep(3000)
If AsyncFileUpload1.HasFile Then
'Dim strPath As String = newPath + Path.GetFileName(e.FileName)
'AsyncFileUpload1.SaveAs(strPath)
Dim fileName = Path.GetFileName(e.FileName)
'Dim imageBytes(AsyncFileUpload1.PostedFile.InputStream.Length) As Byte
'AsyncFileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.length)
Dim imageBytes = AsyncFileUpload1.FileBytes
'AsyncFileUpload1.FileBytes
'// now insert this into the database
Try
Dim sql As String = "INSERT INTO [UploadedFiles] (CustomerID, FileName, FileSize, FileContent, FileType, FileUploadDate, QuoteID)" & _
"VALUES (#CustomerID, #FileName, #FileSize, #FileContent, #FileType, #FileUploadDate, #QuoteID) SELECT SCOPE_IDENTITY()"
Using cn As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionStringLargeTimeout")), _
cmd As New SqlCommand(sql, cn)
cmd.CommandTimeout = "3600"
cmd.Parameters.Add("#CustomerID", SqlDbType.Int).Value = 1
cmd.Parameters.Add("#FileName", SqlDbType.NVarChar).Value = fileName
cmd.Parameters.Add("#FileSize", SqlDbType.NVarChar).Value = AsyncFileUpload1.PostedFile.ContentLength
cmd.Parameters.Add("#FileContent", SqlDbType.VarBinary).Value = imageBytes
cmd.Parameters.Add("#FileType", SqlDbType.NVarChar, 50).Value = AsyncFileUpload1.PostedFile.ContentType
cmd.Parameters.Add("#FileUploadDate", SqlDbType.Date).Value = Date.UtcNow.ToLocalTime
cmd.Parameters.Add("#QuoteID", SqlDbType.Int).Value = QuoteID
cn.Open()
'//grab the ID of this insert.
ArtworkID = Integer.Parse(cmd.ExecuteScalar().ToString())
cn.Close()
End Using
Catch ex As Exception
'// do something with this error!
Response.Write(ex.Message)
End Try
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
'// Populate the database with remaining information
Button1.Text = "Please Wait... Sending Request"
Dim thisConnection As New SqlConnection(ConfigurationManager.AppSettings("quotingSystemConnectionString"))
'Create Command object
Dim nonqueryCommand As SqlCommand = thisConnection.CreateCommand()
Try
' Open Connection
thisConnection.Open()
' 1. Create Command
' Sql Update Statement
Dim updateSql As String = "UPDATE Quote " & _
"SET Status = '2', FirstName = #FirstName, LastName = #LastName, CompanyName = #CompanyName, Email = #Email, Phone = #Phone, Quantity = #Quantity, DesignInfo = #DesignInfo, CS1 = #CS1, CS2 = #CS2, Comments = #Comments " & _
"WHERE QuoteID = " & QuoteID
Dim UpdateCmd As New SqlCommand(updateSql, thisConnection)
' 2. Map Parameters
'UpdateCmd.Parameters.Add("#Status", SqlDbType.Int, "Status")
UpdateCmd.Parameters.Add("#FirstName", SqlDbType.NVarChar, 100, "FirstName")
UpdateCmd.Parameters.Add("#LastName", SqlDbType.NVarChar, 100, "LastName")
UpdateCmd.Parameters.Add("#CompanyName", SqlDbType.NVarChar, 100, "CompanyName")
UpdateCmd.Parameters.Add("#Email", SqlDbType.NVarChar, 200, "Email")
UpdateCmd.Parameters.Add("#Phone", SqlDbType.NVarChar, 30, "Phone")
UpdateCmd.Parameters.Add("#Quantity", SqlDbType.Int, 20, "Quantity")
UpdateCmd.Parameters.Add("#DesignInfo", SqlDbType.NVarChar, 100, "DesignInfo")
UpdateCmd.Parameters.Add("#CS1", SqlDbType.NVarChar, 20, "CS1")
UpdateCmd.Parameters.Add("#CS2", SqlDbType.NVarChar, 20, "CS2")
UpdateCmd.Parameters.Add("#Comments", SqlDbType.NVarChar, 1000, "Comments")
''''''''''''''
'UpdateCmd.Parameters("#Status").Value = 2
UpdateCmd.Parameters("#FirstName").Value = txtFirstName.Text
UpdateCmd.Parameters("#LastName").Value = txtLastName.Text
UpdateCmd.Parameters("#CompanyName").Value = txtCompanyName.Text
UpdateCmd.Parameters("#Email").Value = txtEmailAddress.Text
UpdateCmd.Parameters("#Phone").Value = txtPhoneNumber.Text
UpdateCmd.Parameters("#Quantity").Value = txtQuantity1.Text
UpdateCmd.Parameters("#DesignInfo").Value = drpDesignInfo1.SelectedValue
UpdateCmd.Parameters("#CS1").Value = drpColoursSideOne1.SelectedValue
Dim CS2 As String
If drpDesignInfo1.SelectedValue = "1" Then
CS2 = "na"
Else
CS2 = drpColoursSideTwo1.SelectedValue
End If
UpdateCmd.Parameters("#CS2").Value = CS2
UpdateCmd.Parameters("#Comments").Value = txtComments.Text
'QuoteID
'''''''''''''''
UpdateCmd.ExecuteNonQuery()
Catch ex As SqlException
' Display error
Response.Write("FAIL: " & ex.Message)
Finally
' Close Connection
thisConnection.Close()
Panel1.Visible = True
Panel2.Visible = False
End Try
End Sub
Protected Sub btnRequestAnother_Click(sender As Object, e As System.EventArgs) Handles btnRequestAnother.Click
QuoteID = Nothing
Response.Redirect(Request.RawUrl)
Panel1.Visible = False
Panel2.Visible = True
'IsFirstTime = False
End Sub
Protected Sub drpColoursSideOne1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpColoursSideOne1.SelectedIndexChanged
If drpDesignInfo1.SelectedValue = "2" Then
drpColoursSideTwo1.SelectedValue = drpColoursSideOne1.SelectedValue
End If
End Sub
End Class
Please excuse my messy code...
you can do like this:
static bool IsFirstTime = false;
After this
if(!Page.IsPostBack && !IsFirstTime)
{
insertdata();
IsFirstTime = true;
}
insertdata() inserts data into database.

create a filter row with textboxes on each column in asp.net gridview

I have a asp.net gridview, which i am binding at runtime with a custom List object. I want to add a filter row below the header row on each column and on click of filter button grid data should get filtered based on values written in the filter textboxes. requirement seems weird but this is what client wants. please help with some clue.
aspx code :
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
<HeaderTemplate>
<table>
<tr>
<td align="center">
<asp:ImageButton runat="server" ID="imgFilter1" ImageUrl="../Images/filter.png" Style="height: 20px;
width: 20px;" OnClick="imgFilter1_click" />
</td>
<td align="center">
<asp:TextBox runat="server" ID="gridTextboxFilter1" AutoPostBack="true" onTextChanged="gridTextboxFilter1_text_changed">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="center" colspan="2">
//your column header
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("your_dataFeild") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
cs code :
private void BindGrid(string strFilter)
{
try
{
// Simple created a table to bind with Grid view and
// populated it with data.
DataTable dt = new DataTable("sample");
dt.Columns.Add("ID");
dt.Columns.Add("Name");
DataRow dr ;
for(int counter=1;counter<11;counter++)
{
dr = dt.NewRow();
dr["ID"]=counter.ToString();
dr["Name"]= "Cat" + counter.ToString();
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
if(strFilter != "")
dv.RowFilter="Name like '%" + strFilter + "%'";
if (CategoryFilter == "")
gvCategory.DataSource = dv;
else
gvCategory.DataSource = dv;
gvCategory.DataBind();
}
catch (Exception ex)
{
}
finally
{
}
}
protected void gridTextboxFilter1_text_changed(object sender, EventArgs e)
{
string text = ((TextBox)sender).Text;
BindGrid(text);
}
Add a textbox and button on the header template.
Write a query on button press and get the value.
The query something like select * from tbl where col like '%val%'
Bind the value to gridView.
I think this will solves for you

Resources