What development environment setup steps am I missing? - asp.net

I'm working on a database project for my school's science fair. I need to insert some data from a .aspx webform into an access database. I've been using "Microsoft Visual Web Developer" to write the following .aspx.vb code. However when I press the "submit" button it doesn't send the data to the database as it should.
What development environment setup steps am I missing?
I've been following this tutorial (http://www.youtube.com/watch?v=szm3BFSOVw0).
Here's the aspx source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
}
</script>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"></head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Science Fair Registration</title>
<form id="form1" runat="server" class="auto-style1">
<br />
<%-- Graphics--%>
<center><h1>Science Fair Registration</h1></center>
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<br />
First Name:<br />
<asp:TextBox id="TextBoxSFirst" runat="server" Width="500px"></asp:TextBox>
<br />
Last Name:<br />
<asp:TextBox id="TextBoxSLast" runat="server" Width="500px"></asp:TextBox>
<br />
Student Email Address:<br />
<asp:TextBox id="TextBoxSEmail" runat="server" Width="500px"></asp:TextBox>
<br />
<br />
<br />
School:<br />
<asp:TextBox id="TextBoxSchool" runat="server" Width="500px"></asp:TextBox>
<br />
Grade:<br />
<asp:DropDownList id="DropDownListGrade" runat="server" Width="86px">
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>
<br />
Teacher's Last Name (only):<br />
<asp:TextBox id="TextBoxTLastName" runat="server" Width="500px"></asp:TextBox>
<br />
Teacher E-mail:<br /> <asp:TextBox ID="TextBoxTEmail" runat="server"
Width="500px"></asp:TextBox>
<br />
<%-- Teacher Phone Number:<br /> <asp:TextBox id="TPhone" runat="server" Width="500px"></asp:TextBox> --%>
<%-- Might put the above in later --%>
<br />
<br />Catagory :<br /> <asp:DropDownList id="DropDownListCatagory" runat="server" Width="212px">
<asp:ListItem>Behavorial & Social Sciences</asp:ListItem>
<asp:ListItem>Biochemistry & Microbiology</asp:ListItem>
<asp:ListItem>Botany</asp:ListItem>
<asp:ListItem>Environmental Sciences</asp:ListItem>
<asp:ListItem>Medicine & Health</asp:ListItem>
<asp:ListItem>Zoology</asp:ListItem>
<asp:ListItem>Chemistry</asp:ListItem>
<asp:ListItem>Computer Science</asp:ListItem>
<asp:ListItem>Earth & Space Sciences</asp:ListItem>
<asp:ListItem>Engineering</asp:ListItem>
<asp:ListItem>Mathematics</asp:ListItem>
<asp:ListItem>Physics</asp:ListItem>
</asp:DropDownList>
<br />
Exibit Title :<br /> <asp:TextBox id="TextBoxTitle" runat="server" Width="500px"></asp:TextBox>
<br />
Does your exhibit use electricity?<br />
<%-- Possible issues here, may need to use 1 & 0 instead--%>
<asp:DropDownList id="DropDownListElectricity" runat="server">
<asp:ListItem Value="True">Yes</asp:ListItem>
<asp:ListItem Value="False">No</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<asp:Button id="Button1" runat="server" Text="Submit" onclick="Button1_Click"
style="height: 26px" />
<br />
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
Here is the aspx.vb source:
Imports System
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'form data requests---------------------------------------------------------------------------------------------------------
Dim strName As String = Request.Form("First") 'In paraenthesis may be the item name in the form
Dim strLast As String = Request.Form("Last")
Dim strStudentEmail As String = Request.Form("StudentEmail")
Dim strSchool As String = Request.Form("School")
Dim numGrade As Integer = Request.Form("Grade") '*Dropdown list
Dim strTeacher As String = Request.Form("Teacher") 'Teacher's last name
Dim strTeacherEmail As String = Request.Form("TeacherEmail")
Dim strCatagory As String = Request.Form("Catagory") '*Dropdown list
Dim strTitle As String = Request.Form("Title")
Dim boolElectricity As Boolean = Request.Form("Electricity") '*possible boolean for electricity
'Open Db Connection---------------------------------------------------------------------------------------------------------
Dim strSQL As String
Dim dbconn As OleDbConnection = Nothing
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("sf13.mdb"))
dbconn.Open();
'SQL actions ----------------------------------------------------------------------------------------------------------
strSQL = "insert into Exhibits (First, Last, School, Teacher, Title, Grade, Category, TeacherNumber, StudentEmail, Electricity, TeacherEmail) values (?,?,?,?,?,?,?,?,?,?,?)"
objcmd = New OleDbCommand(strSQL, dbconn) 'OleDbCommand should be highlighted - missing an imports....
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#First", strName))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Last", strLast))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#School", strSchool))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Teacher", strTeacher))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Title", strTitle))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Grade", numGrade))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Category", strCatagory))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#StudentEmail", strStudentEmail))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#Electricity", boolElectricity))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("#TeacherEmail", strTeacherEmail))
objcmd.ExecuteNonQuery()
'Close DB Connection
dbconn.Close()
Response.Write("Thank you for registering")
End Sub
End Class
Fixed it
I changed the language to VB and added a "code behind tag".
<%# Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="ScienceFair.aspx.vb" Inherits="_Default" %>

It looks like you're mixing in-line coding style with code-behind. Try changing the page language to VB and specifying the code-behind class:
<%# Page Language="VB" Inherits="_Default1" %>
Also, remove the script block at the start of the file.
Further Reading
ASP.NET Code-Behind Model Overview

Related

Master Page not working on ASP.NET Page

I'm having trouble with my ASP.NET Webform. All my pages are working perfectly with the master page, but for some reason my ProductItem page isn't accepting the master page.
Heres my code for ProductItem:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ProductItem.aspx.cs" Inherits="mumsBoutique.ProductItem" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<link href="Content/websiteStyle.css" rel="stylesheet" type="text/css" />
<h1><center>Product Details</center></h1>
<div class="row">
<asp:Label ID="productNameLabel" runat="server" Text="Product"></asp:Label>
<br />
<asp:Label ID="productItemNumber" runat="server" Text="ProductCode" CssClass="ProductItem_productNumber"></asp:Label>
</h3>
<h3>
<asp:Label ID="productCost" runat="server" Text="£0.00"></asp:Label>
</h3>
<p>
<asp:Image ID="productImage" runat="server" />
</p>
<h4>Product summary</h4>
<p>
<asp:Label ID="productDescription" runat="server" Text=""></asp:Label>
</p>
<!-- The right colum displays a text box for user to add items to the basket -->
<h3>Buy Item</h3>
<p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="text-danger" />
<p>
Quantity: <asp:TextBox ID="itemQuantity" runat="server" Text="1"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvItemQuantity" runat="server" ErrorMessage="Quantity is required" Text="Please specify the quantity required" ControlToValidate="itemQuantity" CssClass="text-danger" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvItemQuantity" runat="server" ErrorMessage="Invalid quantity value" Text="Please specify a valid numeric quantity value" ControlToValidate="itemQuantity" Type="Integer" Display="Dynamic" CssClass="text-danger" Operator="DataTypeCheck"></asp:CompareValidator>
<asp:RangeValidator ID="rvItemQuantity" runat="server" ErrorMessage="Invalid quantity value" Text="Please specify a quantity value between 1 and 10" ControlToValidate="itemQuantity" Type="Integer" MinimumValue="1" MaximumValue="10" Display="Dynamic" CssClass="text-danger"></asp:RangeValidator>
</p>
<p>
<asp:Button ID="btnAddToBasket" runat="server" Text="Add to basket" CssClass="btn btn-primary btn-lg" OnClick="btnAddToBasket_Click" />
</p>
</div>
</asp:Content>
But I don't think the problem is on this particular page. It seems the problem occurs when I run the page from the hyperlink on the Bags.aspx page
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Bags.aspx.cs" Inherits="mumsBoutique.Bags" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<link href="Content/mumsBoutique.css" rel="stylesheet" type="text/css" />
<h1><center>Bags</center></h1>
<div class="row">
<asp:DataList ID="DataList1" runat="server" CssClass="table ProductsDataList" DataKeyField="productID" DataSourceID="SqlDataSource1" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="200px" Width="180px" ImageUrl='<%# Eval("Picture", "~/{0}") %>' />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("productID", "ProductItem.aspx/{0}") %>' Text='<%# Eval ("productName") %>'></asp:HyperLink>
<br />
Item Number:
<asp:Label ID="ItemNumberLabel" runat="server" Text='<%# Eval("productNumber") %>' />
<br />
<asp:Label ID="CostLabel" runat="server" Text='<%# Eval("cost", "{0:C}") %>' />
<br />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT Items.productID, Items.productName, Items.productNumber, Items.picture, Items.cost, Items.categoryID, ItemCategories.Name AS Expr1 FROM ItemCategories INNER JOIN Items ON ItemCategories.categoryID = Items.categoryID WHERE (Items.categoryID = 2)"></asp:SqlDataSource>
</div>
</asp:Content>
Would really appreciate any help, been stuck for hours!
Update: Here are some screen shots of the problem I mean.
This is the Bags.aspx Page When you click on the hyperlink it takes you to the following
ProductItem.aspxAs can be seen the master page isn't being used for some reason. Yet in all other pages it works perfectly fine.
Here is the ProductItem.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.FriendlyUrls;
using mumsBoutique.Models;
namespace mumsBoutique
{
public partial class ProductItem : System.Web.UI.Page
{
int _productID = 0;
protected void Page_Load(object sender, EventArgs e)
{
IList<string> segments = Request.GetFriendlyUrlSegments();
if (segments != null && segments.Count > 0)
{
// Convert the item ID to an integer and store it in the field _itemID
int.TryParse(segments[0], out _productID);
}
// If no item ID is specified, go back to the products page
if (_productID == 0)
{
Response.Redirect("Products");
}
// If _itemID is a valid value, search the database for the matching item
if (!IsPostBack && _productID > 0)
{
// open the connection to the database
using (ApplicationDbContext context = new ApplicationDbContext())
{
string sql = "SELECT * FROM Items WHERE productId = #productId";
System.Data.SqlClient.SqlParameter parameter = new System.Data.SqlClient.SqlParameter("#productId", _productID);
Item foundItem = context.Database.SqlQuery<Item>(sql, parameter).FirstOrDefault();
productNameLabel.Text = foundItem.productName;
productItemNumber.Text = foundItem.productNumber;
productCost.Text = foundItem.cost.ToString("c");
productImage.ImageUrl = "~/" + foundItem.picture;
productDescription.Text = foundItem.productDecription;
}
}
}
protected void btnAddToBasket_Click(object sender, EventArgs e)
{
// Check if page is valid
if (Page.IsValid)
{
int qty = 0;
// Get the quantity from the input field
qty = int.Parse(itemQuantity.Text);
// Check if item already exist in basket
OrderItem basketItem = ShopApp.Instance.GetBasketItem(_productID);
if (basketItem == null)
{
// item does not currently exist in basket, add new one
using (ApplicationDbContext context = new ApplicationDbContext())
{
// find the product item (pItem) with ItemId matching what is stored in the variable field (_itemId)
Item productItem = context.Items.FirstOrDefault(i => i.productID == _productID);
basketItem = new OrderItem()
{
productId = _productID,
Quantity = qty,
Price = double.Parse(productCost.Text, System.Globalization.NumberStyles.Currency),
Item = productItem
};
ShopApp.Instance.BasketItems.Add(basketItem);
}
}
else
{
// item already exists in basket, increase the quantity
basketItem.Quantity += qty;
}
((SiteMaster)Master).UpdateBasket();
}
}
}
}
It looks like you are trying to pass the productID as a parameter, so try changing NavigateUrl='<%# Eval("productID", "ProductItem.aspx/{0}") %>'
to
NavigateUrl='<%# Eval("productID", "ProductItem.aspx?productID={0}") %>'
Also, you need to move your CSS links to the appropriate place in your master page - you should not be linking to CSS style sheets from within a page when using a master page, and certainly not from within a ContentPlaceHolder section as you are not overriding any styles. This is more than likely the cause of your problem.
UPDATE
I've taken a look at your project and found the following problems, just by eyeballing it (can't run it due to diff DB version, etc):
The markup in your master page is badly formed. You are basically doing everything in the head section because you have no body section.
The link to your style sheet in the master page is outside of the
HTML document - it should be within the head section. Here is how structure of your master page should look:
<%# Master Language="C#" AutoEventWireup="true"
CodeBehind="Site.master.cs" Inherits="mumsBoutique.SiteMaster" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<link href="Content/websiteStyle.css" rel="stylesheet"
type="text/css" />
</head>
<body>
<form id="form1" runat="server">
...
</form>
</body>
Remove the superfluous CSS links from your Bags and ProductItem
pages - when you have fixed the CSS link in the master page, that is
all you should need; you're obviously not overriding anything as you are specifying the same style sheet throughout.

Assigning FormView value to VB variable

I am trying to assign a FormView value to a VB variable.
I am using code that works fine when first_nameTextBox is a TextBox and user enters data directly, but fails when first_nameTextBox is a label populated from a database via FormView.
Error I receive is BC30451: 'FormView2_first_nameTextBox' is not declared. It may be inaccessible due to its protection level.
Any help much appreciated.
The code is below;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Page Language="VB" %>
<%# Import Namespace="System.Net.Mail" %>
<%# Import Namespace="System.Text" %>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<head runat="server">
<!-- Scripting area here -->
<script runat="server" type="text/vbscript">
Protected Sub btnSubmit_click (ByVal sender As Object, ByVal e As EventArgs)
If IsPostBack Then
Dim sc As SmtpClient = New SmtpClient("relay.hostinguk.net")
Dim sb As StringBuilder = New StringBuilder()
Dim msg As MailMessage = Nothing
sb.Append("Name : " + FormView2_first_nameTextBox.Text + vbCrLf)
Try
msg = New MailMessage("from#company.com", _
"to#company.com", "Contact details for Co", _
sb.ToString())
sc.Send(msg)
Catch ex As Exception
' something bad happened
Response.Write("Something bad happened! - please try again")
Finally
Multiview1.SetActiveView(ViewConfirmation)
If Not msg Is Nothing Then msg.Dispose()
End Try
End If
End Sub
Protected Sub Page_Load (ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Try
Multiview1.SetActiveView(ViewForm)
Catch ex As Exception
' something bad happened
Response.Write("Something bad happened! - please try again")
End Try
End If
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:MultiView runat="server" id="MultiView1">
<asp:View runat="server" id="ViewForm">
<asp:AccessDataSource ID="AccessDataSource2bd" runat="server" DataFile="../app_data/bw_data.mdb" SelectCommand="SELECT * FROM student WHERE student_ID = 92">
</asp:AccessDataSource>
<asp:FormView runat="server" id="FormView2" DataSourceID="AccessDataSource2bd" DataKeyNames="student_ID" DefaultMode="ReadOnly">
<ItemTemplate >
<asp:Label id="first_nameTextBox" runat="server" Text='<%# Eval("first_name") %>' />,
</ItemTemplate >
</asp:FormView>
<asp:Table runat="server" id="Table2">
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Left" height="20px">
<asp:Button id="UpdateButton" runat="server" CommandName="Update" onclick="btnSubmit_click" Text="Send Email"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
<asp:View runat="server" id="ViewConfirmation">
<p>An email has been sent, and copied to you, confirming all current contact details.</p>
</asp:View>
<p></p>
</asp:MultiView>
</form>
</body>
</html>
Thanks
Ant
Try this:
dim tb as TextBox = FormView2.Row.FindControl("first_nameTextBox")
sb.Append("Name : " + tb.Text + vbCrLf)

Missing Source code of a published ASP.NET application

I have a web application that is published and working in server. I have aspx files, but I don't have .vb files. I need to edit a singe page in the application. How can I reach to the .vb files ? or better to say that how can I edit the part that I want in the application?
Edit:
Here is my aspx file:
<%# page language="VB" autoeventwireup="false" inherits="UrunRapor, App_Web_hfev-r-q" %>
<%# Register assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %><%# Register assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>
<%# Register assembly="DevExpress.Web.ASPxGridView.v8.3.Export, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView.Export" tagprefix="dxwgv" %>
<!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">
<title>Ürün Detaylı Rapor</title>
<script language="javascript">
window.moveTo(0, 0);
window.resizeTo(screen.availWidth, screen.availHeight);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="font-size: 9pt; width: 474px; font-family: Calibri">
<tr>
<td style="width: 100px; height: 22px">
Ay</td>
<td style="width: 100px; height: 22px">
<asp:DropDownList ID="cboMonth" runat="server" BackColor="#FFFFC0" Font-Bold="True"
Font-Names="Calibri" Font-Size="9pt">
<asp:ListItem Selected="True" Value="%%">[..]</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="05">May</asp:ListItem>
<asp:ListItem Value="06">June</asp:ListItem>
<asp:ListItem Value="07">July</asp:ListItem>
<asp:ListItem Value="08">August</asp:ListItem>
<asp:ListItem Value="09">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px; height: 22px">
Yıl
</td>
<td style="width: 100px; height: 22px">
<asp:DropDownList ID="cboYear" runat="server" BackColor="#FFFFC0" Font-Bold="True"
Font-Names="Calibri" Font-Size="9pt">
<asp:ListItem Selected="True" Value="%%">[..]</asp:ListItem>
<asp:ListItem Value="2007">2007</asp:ListItem>
<asp:ListItem Value="2008">2008</asp:ListItem>
<asp:ListItem Value="2009">2009</asp:ListItem>
<asp:ListItem Value="2010">2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="Sorgula" /></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button2" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="Excel'e aktar" /></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button3" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="PDF dosyasına aktar" Width="123px" /></td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CRRConnectionString %>">
<SelectParameters>
<asp:ControlParameter ControlID="cboMonth" Name="Month" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="cboYear" Name="Year" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<dxwgv:aspxgridview id="dgCRR" runat="server" datasourceid="SqlDataSource1">
<Settings ShowFilterRow="True" ShowFilterRowMenu="True" ShowFilterBar="Visible"
ShowGroupedColumns="True" ShowGroupPanel="True"></Settings>
<SettingsPager Visible="False" PageSize="1000" Position="TopAndBottom"></SettingsPager>
</dxwgv:aspxgridview>
<dxwgv:ASPxGridViewExporter ID="ToExcel" runat="server">
</dxwgv:ASPxGridViewExporter>
</form>
</body>
</html>
Her is my .vb file which I want to use
Imports System.Globalization
Partial Class UrunRapor
Inherits CRR.RequestBase
Dim SelCmd As String
Dim MyUser As String
Dim dtreg As Data.DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyUser = Request.ServerVariables.Get("LOGON_USER")
If Not Page.IsPostBack Then
Dim dareg As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter
dareg.SelectCommand = select_User(Request.ServerVariables.Get("LOGON_USER"))
dareg.SelectCommand.Connection = cnn
dtreg = New Data.DataTable
dareg.Fill(dtreg)
If dtreg.Rows.Count = 0 Then
Response.Redirect("NotAuthRep.aspx")
End If
'Exit Sub
'dgCRR.DataBind()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
FillGrid()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
FillGrid()
ToExcel.FileName = "CRR-Product.pdf"
ToExcel.WritePdfToResponse("CRR-Product.pdf")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'ToExcel.FileName = "CRRNew"
'ToExcel.DataBind()
FillGrid()
ToExcel.GridViewID = "dgCRR"
ToExcel.WriteXlsToResponse()
End Sub
Protected Sub FillGrid()
SelCmd = "SELECT tblCRRProductDetails.CRRId, tblCRRProductDetails.ProductCode, tblCRRProductDetails.ProductName, tblCRRProductDetails.Batch, tblCRRProductDetails.ExpireDate, tblCRRProductDetails.Qty, tblCRRProductDetails.SalesUnit, tblCRR.CrrCaptureDate, tblCRR.RegistrarName, tblCRR.CustomerCode, tblCRR.CustomerName, tblCRR.Channel, tblCRR.ClaimerName, tblCRR.ClaimerAddress, tblCRR.ClaimerPhone, tblCRR.ClaimerMail, tblCRR.CaseDetails, tblCRR.RsDeptName, tblCRR.ReasonName, tblCRR.RsPerName, tblCRR.ExpecRsDay, tblCRR.ExpecRsDate, tblCRR.RsDescription, tblCRR.ResolutionDate, tblCRR.ClaimResult, tblCRR.ActionPlan, tblCRR.ClosedPerName, tblCRR.ClosingDate,tblCRR.Status FROM tblCRRProductDetails INNER JOIN tblCRR ON tblCRRProductDetails.CRRId = tblCRR.CrrID WHERE (MONTH(CrrReceiveDate) LIKE '" & cboMonth.SelectedItem.Value & "') AND (YEAR(CrrReceiveDate) LIKE '" & cboYear.SelectedItem.Value & "')"
SqlDataSource1.ConnectionString = "My Connection String"
SqlDataSource1.SelectCommand = SelCmd
dgCRR.DataBind()
End Sub
End Class
When you publish the site, the compiled version is published on the server, not the code files. You would need Disassembler / Decompiler to decompile the dll files. Some of them are
.Net Reflecter
ILSpy (Free)
Dot Peek (Free)
What you could do is change the ASPX, so for example instead of this:
<%# Page Language="C#" CodeBehind="MyPage.aspx.cs" Inherits="MyNamespace.MyPage" %>
You could change it like this:
<%# Page Language="C#" Inherits="MyOtherNamespace.MyNewPage" %>
Write the new behavior in a new MyOtherNamespace.MyNewPage class (that should derive at least from System.Web.UI.Page) that you can put in any .DLL assembly that you deploy in the bin directory.
You can also derive this new class from the original page (just reference the original assembly) instead of just deriving from System.Web.UI.Page, if deriving is an option for you, depending on the changes you need to do.
Otherwise, you will have to reconstruct the original code using a tool such as .NET Reflector or ILSpy to build this new class, but at least, you don't have to touch the existing compiled assembly.
You could try disassembling it using ilasm and editing the IL directly, but I think realistically you will struggle to make any changes without the source. The .cs files are the source files. Only the compiled IL files will be available on the published site. You will need to find out who published it and speak to them about getting the source.

error with updatepanel

PROBLEM
When i put
<asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload All" /> outside the update panel everything works fine,but as soon as i put it back into the update panel...it stops working.
ASPX CODE
<%# Page Language="VB" AutoEventWireup="false" CodeFile="try.aspx.vb" Inherits="AdminPanel_try" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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">
<title></title>
<script src="../js/multi-upload/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../js/multi-upload/jquery.MultiFile.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload All" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
CODE BEHIND
Partial Class AdminPanel_try
Inherits System.Web.UI.Page
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
' Get the HttpFileCollection
Dim hfc As HttpFileCollection = Request.Files
For i As Integer = 0 To hfc.Count - 1
Dim hpf As HttpPostedFile = hfc(i)
If hpf.ContentLength > 0 Then
hpf.SaveAs(Server.MapPath("MyFiles") & "\" & System.IO.Path.GetFileName(hpf.FileName))
Response.Write("<b>File: </b>" & hpf.FileName & " <b>Size:</b> " & hpf.ContentLength & " <b>Type:</b> " & hpf.ContentType & " Uploaded Successfully <br/>")
End If
Next i
Catch ex As Exception
End Try
End Sub
End Class
NOTE:
i am using this tutorial kindly check this link
The UpdatePanel does not support all ASP.NET controls, FileUpload being one of them (http://msdn.microsoft.com/en-us/library/bb386454.aspx).
There are several examples on the Internet, and even here on StackOverflow, that will show you how to support asynchronous file uploads in ASP.NET.

Making changes to a pre-populated textbox

I have the following webform with textboxes that are pre-populated on page load:
<%# Page Title="" Language="VB" MasterPageFile="~/default.master" AutoEventWireup="true" CodeFile="admin.aspx.vb" Inherits="admin" Theme="G2M" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" Runat="Server">
<label>Username: </label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<label>Password: </label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<label>Product Type: </label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<label>SMTP Default Only: </label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<label>Logo: </label>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<asp:Button ID="submit" Text="Submit changes" runat="server" OnClick="SubmitChanges" />
</form>
</asp:Content>
And the codebehind is as follows:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xmlDoc As New XmlDocument
xmlDoc.Load(Server.MapPath("~/XML_Config/Config.xml"))
Dim configValues As XMLParser = New XMLParser(xmlDoc) ''Instantiate the XMLParser
''Populate textboxes with XML data
TextBox1.Text = configValues.UserName
TextBox2.Text = configValues.Password
TextBox3.Text = configValues.ProductType
TextBox4.Text = configValues.SMTPDefaultOnly
TextBox5.Text = configValues.Logo
End Sub
Public Sub SubmitChanges(ByVal sender As Object, ByVal e As System.EventArgs)
Dim xmlDoc As New XmlDocument
xmlDoc.Load(Server.MapPath("~/XML_Config/Config.xml"))
Dim configValues As XMLParser = New XMLParser(xmlDoc) ''Instantiate the XMLParser
configValues.SMTPDefaultOnly = TextBox4.Text
End Sub
All I'm trying to do is make the values editable so when the form is presented to the user, they can change the values and submit them back to the file. My problem is that when the SubmitChanges function is called, even though I change the value of the textbox, it is still the same. How do I pass a new value, typed into thetextbox, to the function?
Enclose your setter in If Not ispostback in that page load. It's overwriting the boxes.

Resources