Re: Content Page Question
Hey,
Can you help us to help you by showing us the code that you are currently using?
Gary
Re: Content Page Question
---------------- Content Page Code ---------------
Code:
Imports MySql.Data.MySqlClient
Imports System.Data
Partial Class ATBank
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
btnNew.Attributes.Add("onmouseover", "this.src='Images/Buttons/btnNew_b.png'")
btnNew.Attributes.Add("onmouseout", "this.src='Images/Buttons/btnNew_a.png'")
btnSave.Attributes.Add("onmouseover", "this.src='Images/Buttons/btnSave_b.png'")
btnSave.Attributes.Add("onmouseout", "this.src='Images/Buttons/btnSave_a.png'")
btnEdit.Attributes.Add("onmouseover", "this.src='Images/Buttons/btnEdit_b.png'")
btnEdit.Attributes.Add("onmouseout", "this.src='Images/Buttons/btnEdit_a.png'")
btnCancel.Attributes.Add("onmouseover", "this.src='Images/Buttons/btnCancel_b.png'")
btnCancel.Attributes.Add("onmouseout", "this.src='Images/Buttons/btnCancel_a.png'")
txtBalance.Style("TEXT-ALIGN") = TextAlign.Right.ToString
InitFields()
End If
Me.Session("Clicked") = "lnkATBank"
End Sub
Private Sub InitFields()
Dim region As String = Session("region")
If region = Nothing Then
Exit Sub
End If
Dim myBank As New Bank
myBank = Session("myBank")
Dim cls As New CommonMySql
Dim NewBankNo As String = cls.GetNewBankNo(region)
If Not IsNothing(myBank) Then
myBank.AcctCode = NewBankNo
txtBankAcctCode.Text = "B" & myBank.AcctCode
txtBankCode.Text = myBank.BankCode
lblBankName.Text = myBank.BankName
txtAccountNo.Text = myBank.AcctNo
Else
myBank = New Bank
Session("myBank") = myBank
Response.Redirect(Request.Url.ToString(), False)
End If
If Session("myBank") IsNot Nothing Then
myBank = Session("myBank")
Me.txtBankAcctCode.Text = myBank.AcctCode
Me.txtCurrencyCode.Text = myBank.CurrencyCode
Me.txtBankCode.Text = myBank.BankCode
Me.lblBankName.Text = myBank.BankName
Me.txtAccountNo.Text = myBank.AcctNo
Me.txtContactNo.Text = myBank.Contact
Me.txtBalance.Text = myBank.Balance
If myBank.IsActive = True = True Then
Me.ckStatus.Checked = True
Else
Me.ckStatus.Checked = False
End If
End If
Dim conString As String
conString = ConnectionString.GetInstance("TWS").ConStr
Dim dr As MySqlDataReader
Dim con As MySqlConnection = New MySqlConnection(conString)
con.Open()
Dim command As MySqlCommand = New MySqlCommand("tws_get_max_acct_code", con)
command.CommandType = Data.CommandType.StoredProcedure
dr = command.ExecuteReader
If Not dr.Read Then
Me.txtBankAcctCode.Text = "B0001"
Else
Me.txtBankAcctCode.Text = dr.Item(0)
myBank.AcctCode = Me.txtBankAcctCode.Text
End If
dr.Close()
con.Close()
If Session("currencycode") IsNot Nothing Then
Me.txtCurrencyCode.Text = Session("currencycode")
End If
Dim mybnk As New Bank
If Session("mybnk") IsNot Nothing Then
mybnk = Session("mybnk")
Me.txtBankAcctCode.Text = mybnk.AcctCode
Me.txtCurrencyCode.Text = mybnk.CurrencyCode
Me.txtBankCode.Text = mybnk.BankCode
Me.lblBankName.Text = mybnk.BankName
Me.txtAccountNo.Text = mybnk.AcctNo
Me.txtContactNo.Text = mybnk.Contact
Me.txtBalance.Text = String.Format("{0:0,0.00}", mybnk.Balance)
If mybnk.IsActive = True = True Then
Me.ckStatus.Checked = True
Else
Me.ckStatus.Checked = False
End If
End If
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Me.Session.Add("pagebeforesearch", GetCurrentPageName)
btnSearchAcct.Attributes.Add("onclick", "openBankAccountCode(); return false")
btnSearchBank.Attributes.Add("onclick", "openBank(); return false")
btnSearchCurrency.Attributes.Add("onclick", "openCurrency(); return false")
End Sub
Private Function GetCurrentPageName() As String
Dim sPath As String = System.Web.HttpContext.Current.Request.Url.AbsolutePath
Dim oInfo As System.IO.FileInfo = New System.IO.FileInfo(sPath)
Dim sRet As String = oInfo.Name
Return sRet
End Function
Private Sub Redirect()
Session("myBank") = Nothing
Session("mybnk") = Nothing
Session("currencycode") = Nothing
Session("pagebeforesearch") = Nothing
Response.Redirect(GetCurrentPageName, False)
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSave.Click
Try
If Session("IsEdit") = True Then
update_bank_details(Me.txtBankAcctCode.Text.Trim, Me.ckStatus.Checked)
MsgBox("Successfully Updated.", MsgBoxStyle.OkOnly, "Confirmation")
Exit Try
End If
If MsgBox("Do you want to save transaction?", MsgBoxStyle.YesNo, "Save") = MsgBoxResult.Yes Then
InsertIntoTables()
MsgBox("Saving Successfull", MsgBoxStyle.OkOnly, "Confirmation")
Redirect()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub update_bank_details(ByVal p_acctcode As String, ByVal p_status As Boolean)
Dim conString As String
conString = ConnectionString.GetInstance("TWS").ConStr
Dim con As MySqlConnection = New MySqlConnection(conString)
con.Open()
Dim command As MySqlCommand = New MySqlCommand("tws_bank_details_update", con)
command.CommandType = Data.CommandType.StoredProcedure
command.Parameters.Add(New MySqlParameter("?p_acct_code", MySqlDbType.VarChar, 5))
command.Parameters.Add(New MySqlParameter("?p_isactive", MySqlDbType.Bit, 1))
command.Parameters.Add(New MySqlParameter("?p_res_id", MySqlDbType.Int32))
command.Parameters(0).Value = p_acctcode
command.Parameters(1).Value = p_status
command.Parameters(2).Value = Session("resid")
command.ExecuteNonQuery()
con.Close()
End Sub
Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnEdit.Click
Session.Add("IsEdit", True)
ckStatus.Enabled = True
End Sub
End Class
Re: Content Page Question
------------------- Window Page Code ----------------
Code:
Imports System.Data
Partial Class windowpage_TransNo
Inherits System.Web.UI.Page
Protected Sub btnSearchUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchAccountCode.Click
findTransNo()
End Sub
Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
findTransNo()
End Sub
Protected Sub gvTransNo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvAccountCode.SelectedIndexChanged
Dim bnk As New Bank
Dim dset As New DataSet
dset = Session("searchDs")
bnk.AcctCode = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("AccountCode")
bnk.CurrencyCode = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("CurrencyCode")
bnk.BankCode = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("BankCode")
bnk.BankName = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("BankName")
bnk.AcctNo = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("AccountNo")
bnk.Contact = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("ContactNo")
bnk.Balance = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("OpeningBal")
bnk.IsActive = dset.Tables(0).Rows(gvAccountCode.SelectedIndex)("Active")
Session("mybnk") = bnk
Response.Write("<script language=javascript>")
Response.Write("parent.userswindow.hide()")
Response.Write("</script>")
End Sub
Protected Sub findTransNo()
Dim region As String = Me.Session("region")
If region = Nothing Then Exit Sub
region = region.ToString.ToUpper
Dim currPage As String = Me.Session("pagebeforesearch")
Dim accountCode As String = txtAccountCode.Text.Trim
Dim sql As String = ""
If accountCode = "" Then
sql = "Select AccountCode,CurrencyCode,BankCode,BankName,AccountNo,ContactNo,OpeningBal,Active From twsbankdetails"
Else
sql = "Select AccountCode,CurrencyCode,BankCode,BankName,AccountNo,ContactNo,OpeningBal,Active From twsbankdetails where AccountCode like '%" & accountCode & "%'"
End If
Try
Dim ds As DataSet
ds = DataRetriever.Execute_DataSet(sql, "TWS")
gvAccountCode.DataSource = ds
gvAccountCode.DataBind()
gvAccountCode.Columns(2).Visible = False
gvAccountCode.Columns(3).Visible = False
gvAccountCode.Columns(6).Visible = False
gvAccountCode.Columns(7).Visible = False
gvAccountCode.Columns(8).Visible = False
Session.Add("searchDs", ds)
Catch ex As Exception
Response.Write("<script language=javascript>")
Response.Write("alert('" & ex.ToString & "')")
Response.Write("</script>")
End Try
End Sub
End Class
Re: Content Page Question
Hey,
First up, don't use Response.Write to inject JavaScript onto your page. You the built in methods to do this, i.e.
http://msdn.microsoft.com/en-us/libr...riptblock.aspx
and
http://msdn.microsoft.com/en-us/libr...tupscript.aspx
I don't know if this is the root of the problem that you are facing, but it certainly a place to start.
Gary
Re: Content Page Question
You know there's an easier way to do that. On the spot where you want it injected onto yoru page do <% var_name %> then in the .vb file make a string..
For Example:
In .vb file
dim hworld as string = "Hello World"
on the aspx file:
<% hworld %>
This is nice because you can build your script or whatever else you want as the procedure is processing.
Re: Content Page Question
Hey,
This may be "nice", but that doesn't necessarily mean that it is best practice.
Combining server side code with ASPX markup is bad for a number of reasons, and IMO, should be avoided.
Gary
Re: Content Page Question
What does IMO stand for? Also why is it bad? There's no real way to hack unless you let the user have access to variables you use for the string. As long as you control everything on how you inject it from the back you should be fine from a hacking perspective.
Re: Content Page Question
IMO - In My Opinion.
Rather than repeat what is already on the net, have a look at this article, by our friendly neighbourhood frog, Mendhak:
http://www.codeguru.com/vb/vb_intern...cle.php/c14739
Especially page 4.
Gary
Re: Content Page Question
Ok, I see your point, but sometimes it's just easier to do it than to go some other way. In my case I use a java library called highcharts on letstrend.com. This creates the graphs for my stocks on the aspx page. But before I can create the graphs I have to grab the data from Yahoo, then process it, format it so that I can use the highcharts library. All that is done in real time and in the background. There's no way to do it in the aspx file.
Re: Content Page Question
Quote:
Originally Posted by
jakkjakk
Ok, I see your point, but sometimes it's just easier to do it than to go some other way.
But this is my point...
Just because something is "easier", doesn't mean that it is the right way to do it.
Gary