Java script alert msg in code behind Asp.net 3.5 - asp.net

How to use Java script alert msg in code behind? This message will be display after save the data.
Here is my code,
enter code here
Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add.Click
'add new class
Dim DbClassMst = New ClassMst()
Dim dsClass As DataSet
Dim status As Integer = 0
Dim ResourceObject As Object
' 画面リソース定義
If SessionCtl.GetSession("RES_LANG").ToString = ResourceBase.LOCALE_JA Then
ResourceObject = New ResourceJa(SessionCtl.GetSession("RES_LANG"))
Else
ResourceObject = New ResourceEn(SessionCtl.GetSession("RES_LANG"))
End If
If NewClass.Text = "" Then
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_REG)
Exit Sub
Else
'check to allow unique class
dsClass = DbClassMst.DisplayClass1(NewClass.Text)
If Trim(dsClass.Tables(0).Rows.Count > 0) Then
status = 1
End If
If dsClass.Tables(0).Rows.Count < 10 Then
If status = 0 Then
'insert class
DbClassMst.InsertClassNew(NewClass.Text, dsClass.Tables(0).Rows.Count + 1)
PopulateClassName()
NewClass.Text = ""
Dim AlertMsg As String = ""
AlertMsg = "<script language='javascript'>alert('Data has been saved');</script>"
*********Here I need alert msg.
Else
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_EXIST)
Exit Sub
End If
Else
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_MAX)
End If
End If
End Sub
but is not working. give me an idea.

A better way to do this is to have this as a utility method in a common class:
Friend Module MyUtilities
Public Sub Alert(ByVal page As Page, ByVal message As String)
Dim alertMessage As String = "alert('" & message & "');"
page.ClientScript.RegisterStartupScript(page.[GetType](), "showAlert", alertMessage, True)
End Sub
End Module
This can be used in a page like this:
MyUtilities.Alert(Me, "Sample alert!!!!!")
Your code looks so simpler. Hope this helps!

You should register this script to your page, so this script will be sent to the client.
Page.ClientScript.RegisterStartupScript(typeof(YourPage),
"myScripts",
"<script language='javascript'>alert('Data has been saved');</script>");

Dim someScript As String = ""
someScript = "alert('Your Leave request has been registered');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "onload", someScript)

Related

From a payment platform redirecting to display receipt on another page doesn't occur

I have been using response.redirect for ages but on that opportunity, it doesn't work as expected.
The situation is simple I have got a form, Pay40.aspx, where the user click on apay button, the payment is processed and I am getting back the information from the server. In my process, I want to redirect to another page to display a receipt. But it doesn't. Instead of being redirected to PayFinal.aspx I am seeing in the address Pay40.aspx/PayFinal.aspx?Payment=OK&Order=OC00011 . I tried doing a server.transfer but got the same issue
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
If Not Me.IsPostBack Then
Dim RandomGenerator As New Random()
txtSession.Text = RandomGenerator.Next(999999999).ToString()
End If
If InStr(HttpContext.Current.Request.Url.AbsolutePath, "NormalReturn") > 0 Then
Dim result = (New Transaction()).Commit(Request("token_ws"))
If result.ResponseCode.ToString = 0 And result.Status.ToString = "AUTHORIZED" Then
Response.Redirect("PayFinal.aspx?Payment=OK&Order=" & result.BuyOrder.ToString)
Response.End()
Else
Response.Redirect("PayFinal.aspx?Payment=KO&Order=" & result.BuyOrder.ToString)
Response.End()
End If
End If
End Sub
Private Sub btnPay_Click(sender As Object, e As EventArgs) Handles btnPay.Click
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
Dim vHttpHost As String = System.Web.HttpContext.Current.Request.ServerVariables("HTTP_HOST").ToString()
Dim vSelfURL As String = System.Web.HttpContext.Current.Request.ServerVariables("URL").ToString()
Dim sample_baseurl As String = "http://" + vHttpHost + vSelfURL + "/NormalReturn"
Dim tx = New Transaction(New Options(IntegrationCommerceCodes.WEBPAY_PLUS, IntegrationApiKeys.WEBPAY, WebpayIntegrationType.Test))
Dim response = tx.Create(txtOrder.Text, txtSession.Text, txtAmount.Text, sample_baseurl)
Dim vAction As String = IIf(Not String.IsNullOrEmpty(HttpContext.Current.Request.QueryString("action")), HttpContext.Current.Request.QueryString("action"), "init")
Dim myremotepost As cRemotePost = New cRemotePost
myremotepost.Url = response.Url
myremotepost.Add("token_ws", response.Token)
myremotepost.Post()
End Sub
I have fixed my issue. It was coming from this line of code
Dim sample_baseurl As String = "http://" + vHttpHost + vSelfURL + "/NormalReturn"
By changing it to
Dim sample_baseurl As String = "http://" + vHttpHost + vSelfURL
And changing the Page_Load accordingly solved it. My mistake.

On Button click change Button value text

I have response form in asp.net. I want on send button click the button text should change from send to please wait & once it is send it should back to it's default value text 'send'. can any one help?
code
Protected Sub submit_client_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_client.Click
Try
Dim pattern As String
pattern = "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
If Regex.IsMatch(TextBox3.Text, pattern) Then
Label2.Text = ""
Else
Label2.Text = "Not a valid Email address "
End If
Dim emails As New List(Of String)()
generate.Visible = True
clear.Visible = True
SendHTMLMail()
'For Each item As ListViewItem In lvCustomers.Items
' Dim ck As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
' If ck.Checked Then
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
try like this:
MyButton.Text="Sending"
SendHTMLMail()
Thread.Sleep(3000) // add this & remove SendHTMLMail() for testing
MyButton.Text="Send"

ASP.net Vb.Net Label.Text not updating

In my VB.net ASP application, i have some ASPTREEVIEW where, on page load there is a Label, to which i set some value. After clicking on any row, i catch that value & assign it to the label.
But suddenly that label value is not updating by the chosen value. As if i check it via debugging the value, the value changes, but when i use Lable.text = chosen_value... It sets the value, but it is not actually changing on the html page. HTML shows the old value.
What will be the problem, i am not getting it.
Imports DevExpress
Imports DevExpress.Xpo
Imports DevExpress.Data
Imports DevExpress.Data.Filtering
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Public testvar As Integer = 35
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xpcol As New XPCollection(Of WCSOEE.WcsGCObject)
Dim GCObj1 As WCSOEE.WcsGCObject
Dim Filter1 As New DevExpress.XtraCharts.DataFilter
Dim SelectedGCObject As WCSOEE.WcsGCObject
Filter1.ColumnName = "Oid"
Filter1.Condition = XtraCharts.DataFilterCondition.Equal
Filter1.Value = Label2.Text
If Label2.Text = "" Then
Label2.Text = 10
End If
For Each Siris As DevExpress.XtraCharts.Series In WebChartControl1.Series
' WebChartControl1.Series(Siris.Name).DataFilters.Item(0).Value = CInt(Label2.Text)
Next
Dim masterKeyvalue As DevExpress.Web.ASPxTreeList.TreeListNode = ASPxTreeList1.FocusedNode
If masterKeyvalue IsNot Nothing Then
SelectedGCObject = masterKeyvalue.DataItem
Else
SelectedGCObject = xpcol.Object(31)
End If
' MsgBox(SelectedGCObject.GCName)
MsgBox(Label2.Text)
If IsPostBack = False Then
Label2.Text = calculatehours(SelectedGCObject.Oid)
End If
End Sub
Protected Function calculatehours(Oid As Integer)
xpocolLogAvailability.Session = DevExpress.Xpo.XpoDefault.Session
Dim logavail As New XPCollection(Of WCSOEE.LogAvailability)
Dim gcobjlist As New XPCollection(Of WCSOEE.WcsGCObject)
gcobjlist.Filter = CriteriaOperator.Parse("[Oid]=?", Oid)
Dim filter As CriteriaOperator
Dim ds As New DataTable
Dim Series As New DevExpress.XtraCharts.Series
Dim Filter1 As New DevExpress.XtraCharts.DataFilter
' Label2.Text = Oid
logavail.Filter = CriteriaOperator.Parse("GCObject.Oid=?", Oid)
Filter1.ColumnName = "Oid"
Filter1.Condition = XtraCharts.DataFilterCondition.Equal
Filter1.Value = Oid
Dim arr1(32) As Long
'For i As Int16 = 1 To 32
' arr1(i) = 0
'Next
'For Each gcobj As WCSOEE.LogAvailability In logavail
' arr1(gcobj.Status) = arr1(gcobj.Status) + gcobj.Duration
'Next= ""
'ds.Columns.Add(New DataColumn("Name", System.Type.GetType("System.Int32")))
For Each Siris As DevExpress.XtraCharts.Series In WebChartControl1.Series
WebChartControl1.Series(Siris.Name).DataFilters.Item(0).Value = Oid
Next
WebChartControl1.RefreshData()
'For i As Int16 = 1 To 32
' ds.Rows.Add(i, arr1(i))
'Next
'ASPxListBox1.DataSource = ds
'ASPxListBox1.DataBind()
Return Oid
End Function
Protected Sub ASPxTreeList1_CustomCallback(sender As Object, e As DevExpress.Web.ASPxTreeList.TreeListCustomCallbackEventArgs) Handles ASPxTreeList1.CustomCallback
End Sub
Protected Sub ASPxTreeList1_FocusedNodeChanged(sender As Object, e As System.EventArgs) Handles ASPxTreeList1.FocusedNodeChanged
Dim masterKeyvalue As DevExpress.Web.ASPxTreeList.TreeListNode = ASPxTreeList1.FocusedNode
Dim SelectedGCObject As WCSOEE.WcsGCObject = masterKeyvalue.DataItem
' MsgBox(SelectedGCObject.GCName)
If IsPostBack Then
Label2.Text = calculatehours(SelectedGCObject.Oid)
End If
MsgBox(IsPostBack)
MsgBox(Label2.Text)
End Sub
End Class
Post some code so we can see exactly what your doing, without seeing anything so far ensure you have an If statement in your page load to only apply the label text if the current request is not a postback other wise the the label will be set to this on every request.
If Not IsPostBack() Then
lblSomeLabel.Text = "Page load text"
End If

ASP.NET Control added to Placeholder lost values right after adding

Working over 5 hours on the following problem:
Private Sub ModulEdit_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit
Dim modulid As Integer = 1
loadeditors(modulid)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Sub loadeditors(modulID As Integer)
PlaceHolder1.Controls.Clear()
Using dbContext As New EntitiesModel()
Dim mps As List(Of ef.Modulparameter) = dbContext.Modulparameters.Where(Function(c) c.ModulID = modulID).ToList
Dim mmid As Int16
If EditMode.Checked = True Then
mmid = RadComboBox3.SelectedValue
End If
Dim mp As ef.Modulparameter
For Each mp In mps
Dim lbl As New Label
lbl.Text = "<BR>" & mp.Name & "<BR>"
PlaceHolder1.Controls.Add(lbl)
Select Case mp.Editor.Name
Case "textbox1line"
Dim con As New TextBox
con.ID = mp.ID
If EditMode.Checked = True Then
Using dbContext2 As New EntitiesModel
Try
Dim mpa As ef.Menu_modul_paramvalue = dbContext2.Menu_modul_paramvalues.Where(Function(c) c.ModulparameterID = mp.ID And c.Menu_modulID = mmid).First
con.Text = mpa.Valuestring
Catch ex As Exception
con.Text = "AAAA"
End Try
End Using
End If
PlaceHolder1.Controls.Add(con)
'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(Panel1, con, Nothing)
'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(con, con, Nothing)
Case "radeditor"
Dim con As New RadEditor
con.ID = mp.ID
con.ToolsFile = "\admin\controls\ToolsFile.xml"
'con.CssFiles.Add("\Content\frenzy\css\frenzy-orange.css")
If EditMode.Checked = True Then
Using dbContext2 As New EntitiesModel
Try
Dim mpa As ef.Menu_modul_paramvalue = dbContext2.Menu_modul_paramvalues.Where(Function(c) c.ModulparameterID = mp.ID And c.Menu_modulID = mmid).First
con.Content = mpa.Valuestring
Catch ex As Exception
con.Content = "BBBB"
End Try
End Using
End If
PlaceHolder1.Controls.Add(con)
'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(Panel1, con, Nothing)
'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(con, con, Nothing)
End Select
Next
End Using
End Sub
I add the control dynamicly, calling the codepart above in pre_init (tryed in load and init too with same result)
The value (text) for the control is there until that line PlaceHolder1.Controls.Add(con)
After the con.text is empty.
The control is added after, but with no value.
Strange, that in the same proc i add another control (label), where the text value is on the page after.
Adding additional info:
the control value (text or content), when debugging the LoadEditors), is allways correctly set. But then on the page both (textbox and radeditor) are empty
The routing is called from pre init, as described in a lot of related posts.
You are calling loadeditors in ModulEdit_Init. Shouldn't this be LoadControls ?
I fixed it myself:
Adding "con.ViewStateMode = System.Web.UI.ViewStateMode.Disabled" before adding control to placeholder
Calling "loadeditors()" in RadComboBox3 too
much probably the problem was, that i loaded editors in page-load or init, which got the correct values, but then the RadComboBox3.SelectedIndexChanged event was called, which overwrote the values somehow
So my answer is not a real answer, but it works now (I hate such: it works, but i dont know why) ;)

How to sort a gridview once a radio button is selected

I'm trying to sort records in the gridview right after a radio button is selected. My approach is with the dataview, but because the dataset variable doesn't survive a round trip to the server, I don't know how to make this happen. please help!
Public Sub GetCustomers()
db.RunProcedure("usp_customers_get_all")
db.doSort(radList.SelectedValue)
gvCustomers.DataSource = db.MyView
End Sub
Protected Sub radList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radList.SelectedIndexChanged
If radList.SelectedValue = 0 Then
db.doSort(0)
gvCustomers.DataSource = db.MyView
End If
If radList.SelectedValue = 1 Then
db.doSort(1)
gvCustomers.DataSource = db.MyView
End If
End Sub
Public Sub doSort(ByVal strIn As Integer)
If strIn = 0 Then
MyView.Sort = "lastname, firstname"
Else
MyView.Sort = "username"
End If
End Sub
Public Sub RunProcedure(ByVal strName As String)
Dim objConnection As New SqlConnection(mstrConnection)
Dim mdbDataAdapter As New SqlDataAdapter(strName, objConnection)
Try
mdbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
Me.mDataset.Clear()
mdbDataAdapter.Fill(mDataset, "tblCustomers")
MyView.Table = mDataset.Tables("tblCustomers")
Catch ex As Exception
Throw New Exception("stored procedure is " & strName.ToString & " error is " & ex.Message)
End Try
End Sub
You could store the dataset in one of the following places and then when the post back happens just load it again from there. I have done many of these on a corporate intranet.
Session Variable
ViewState
QueryString
Cache
I cant really provide more help as you didn't specify if this is done in Ajax or if you do a full postback etc. If you provide more info I would love to help you.

Resources