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.
Related
I'm making E-Commerce website. Under that I want to show particular product details. From query string I can do that but that is not seo friendly so I need to make product name in url(from db) instead of using querystring. I tried following code but it is not working for me.
Error - The resource could not be Found
Global.asax
<%# Application Language="VB" %>
<%# Import Namespace="System.Web.Optimization" %>
<%# Import Namespace="System.Web.Routing" %>
<script runat="server">
Sub Application_Start(sender As Object, e As EventArgs)
RouteConfig.RegisterRoutes(RouteTable.Routes)
BundleConfig.RegisterBundles(BundleTable.Bundles)
End Sub
Private Shared Sub RegisterRoutes(routes As RouteCollection)
routes.MapPageRoute("product-detail", "{product_name}.aspx", "product-detail.aspx")
End Sub
</script>
product-detail.aspx (Dynamic Page)
Private Sub product_detail_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim pageName As String = Me.Page.RouteData.Values("product_name").ToString()
End If
End Sub
shop.aspx (used listview control to display list of products)
<asp:ListView ID="products" runat="server" DataKeyNames="ID">
<ItemTemplate>
<asp:HyperLink ID="productID" runat="server" NavigateUrl='<%# Eval("product_name", "~/{0}") %>' CssClass="product-link">
<!--blocks-starts--><div class="blocks blocks-shop">
<asp:Image ID="readyStock" runat="server" ImageUrl="images/common/ready_stock_tag.png" Visible="false" CssClass="tag" />
<asp:Label ID="checkReadyStock" runat="server" Visible="false"></asp:Label>
<div class="block-img">
<img src='<%# Eval("image") %>' runat="server" id="proImg" />
</div>
<div class="block-content">
<span class="sku" style="font-size:0.6em !important">Item No. <asp:Label ID="skuID" runat="server" Text='<%# Eval("sku") %>'></asp:Label></span>
<h3>
<asp:Label ID="prodName" runat="server" Text='<%# Eval("product_name") %>'></asp:Label></h3>
<p><strong>
<asp:Label ID="priceRange" runat="server" Text='<%# Eval("price_range") %>'></asp:Label></strong></p>
</div>
</div><!--blocks-ends-->
</asp:HyperLink>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<div runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
</asp:ListView>
shop.aspx.vb
Private Sub shop_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Try
Dim str As String = "select * from products where status = 'active'"
Dim cmd As New MySqlCommand(str, con)
con.Open()
Dim da As New MySqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
products.DataSource = dt
products.DataBind()
con.Close()
Catch ex As Exception
Response.Write(ex)
End Try
End If
End Sub
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)
I've written a simple webForm that contains 1 textbox and a ReportViewer (created by Reoprt Wizard). I'm receiving no errors when attempting to execute the report, but the report never stops loading. I've double checked the .rdlc file (by previewing the .xsd file and it displays the expected data. So, I set up a breakpoint in my code behind to see if I could identify the problem. Somehow, the code successfully completes and refreshes the ReportViewer code, and then goes into a Designer.vb file to run 4 functions, and then back to the ReportViewer code again. I don't understand what is happening in the Designer.vb code. Could someone please help me understand what I've done wrong? I'll include the ASP.net, vb code behind, and the 4 blocks of code from the Designer.vb file.
ASP.net Code:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/HRMaster.Master" CodeBehind="VacationSick_EmployeeReportByArea.aspx.vb" Inherits="CEI_PerformanceReviews.VacationSick_EmployeeReportByArea" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HRPlaceHolder" runat="server">
<asp:Label ID="Label2" runat="server" style="z-index: 1; left: 74px; top: 215px; position: absolute" Text="Year:"></asp:Label>
<p>
</p>
<asp:DropDownList ID="ddl_Year" runat="server" DataSourceID="YearChooser" DataTextField="PeriodYYYY" DataValueField="PeriodYYYY" style="z-index: 1; left: 129px; top: 214px; position: absolute">
</asp:DropDownList>
<asp:SqlDataSource ID="YearChooser" runat="server" ConnectionString="<%$ ConnectionStrings:CafeWorksConnectionString %>" SelectCommand="SELECT DISTINCT PeriodYYYY
FROM Ted.CafeWorks.dbo.FatzPeriodDates
WHERE PeriodYYYY >= (DATEPART(YEAR, GetDate())-2)
ORDER BY PeriodYYYY DESC"></asp:SqlDataSource>
<asp:Button ID="btn_Refresh" runat="server" style="z-index: 1; left: 269px; top: 212px; position: absolute" Text="Refresh" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="XX-Large" ForeColor="#000099" style="z-index: 1; left: 0px; top: 142px; position: absolute; width: 1179px; text-align: center" Text="Employee Vacation/Sick Days by Area Report"></asp:Label>
<rsweb:ReportViewer ID="rv_EmployeeReportByArea" runat="server" Font-Names="Verdana" Font-Size="8pt" style="z-index: 1; left: 29px; top: 280px; position: absolute; height: 400px; width: 710px" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<LocalReport ReportEmbeddedResource="CEI_PerformanceReviews.VacationSick_ReportByArea.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="Dilbert_VacationSickByArea" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>
VB Code Behind:
Imports Microsoft.Reporting.WebForms
Public Class VacationSick_EmployeeReportByArea
Inherits System.Web.UI.Page
'Declare Variables
Dim Choose_Year As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Default the Year in ddl to this year
If (Page.IsPostBack) = False Then
ddl_Year.SelectedValue = Now.Year
End If
'When the page loads, fill the report with the current year's data
Choose_Year = ddl_Year.SelectedValue.ToString()
rv_EmployeeReportByArea.LocalReport.ReportPath = "VacationSick\VacationSick_ReportByArea.rdlc"
Dim Param As New ReportParameter("Year", "2014")
rv_EmployeeReportByArea.LocalReport.SetParameters({Param})
rv_EmployeeReportByArea.ServerReport.Refresh()
End Sub
These 4 Code Blocks from the file Dilbert_VacationSickByArea.Designer.vb are executed and then it goes back to the PageLoad code for the ReportViewer:
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property ClearBeforeFill() As Boolean
Get
Return Me._clearBeforeFill
End Get
Set
Me._clearBeforeFill = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected ReadOnly Property CommandCollection() As Global.System.Data.SqlClient.SqlCommand()
Get
If (Me._commandCollection Is Nothing) Then
Me.InitCommandCollection
End If
Return Me._commandCollection
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
Try printing your report only If Not Me.Page.IsPostBack.
You can also remove rv_EmployeeReportByArea.ServerReport.Refresh() because you're using a LocalReport.
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
I just want to know how to add a button that has a removechild() or replacechild() function on my XML. Been searching for this for a week now.
Any suggestions would be greatly appreciated. Thanks :)
This is my xml file content
<?xml version="1.0" encoding="utf-8"?>
<theNews>
<news>
<contents>News3 Contents</contents>
<title>News3 Title</title>
<pubDate>February 13, 2012</pubDate>
</news>
<news>
<contents>News2 Contents</contents>
<title>News2 Title</title>
<pubDate>February 1, 2012</pubDate>
</news>
<news>
<contents>News1 Contents</contents>
<title>News1 Title</title>
<pubDate>January 22, 2012</pubDate>
</news>
</theNews>
This is the code for my News Updater
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="NewsUpdater.aspx.vb" Inherits="NewsUpdater" %>
<%-- Add content controls here --%><asp:Content ID="Content1" runat="server"
contentplaceholderid="ContentPlaceHolder1">
<p>
</p>
<table align="center" style="width: 63%">
<tr>
<td align=center>
<div>
<h3>News Title</h3>
<asp:TextBox runat="server" ID="txtTitle" Width="308px"></asp:TextBox>
<br />
<h3>News Content</h3>
<asp:TextBox runat="server" ID="txtContents" TextMode="MultiLine" Height="119px" Width="513px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Update News" />
</div></td>
</tr>
</table>
<p>
<br />
</p>
And this is the code behind the NewsUpdater button
Partial Class NewsUpdater
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmlFile As New System.Xml.XmlDocument()
xmlFile.Load("D:\My Documents\PresentableII\NewsContent.xml")
Dim theNewsTag As System.Xml.XmlElement = xmlFile.CreateElement("news")
Dim theTitleTag As System.Xml.XmlElement = xmlFile.CreateElement("title")
Dim theContentsTag As System.Xml.XmlElement = xmlFile.CreateElement("contents")
Dim theTitleText As System.Xml.XmlText = xmlFile.CreateTextNode(txtTitle.Text)
Dim theContentsText As System.Xml.XmlText = xmlFile.CreateTextNode(txtContents.Text)
theTitleTag.PrependChild(theTitleText)
theContentsTag.PrependChild(theContentsText)
theNewsTag.PrependChild(theTitleTag)
theNewsTag.PrependChild(theContentsTag)
xmlFile.DocumentElement.PrependChild(theNewsTag)
xmlFile.Save("D:\My Documents\PresentableII\NewsContent.xml")
Response.Redirect("NewsFrame.aspx")
End Sub
I want to add another button that has a function of remove or replace the last/latest entry to the xml.
So would this line do what you want?
xmlFile.DocumentElement.RemoveChild(xmlFile.DocumentElement.LastChild)
xmlFile.DocumentElement.AppendChild(your_replacement_element)