I have a Gridview, and one button.
when i click button then show message, but after that my Gridview's format is not correct as before.
please view more in below picture:
Gridview incorrect format after close message
I using this code below to show message:
HttpContext.Current.Response.Write("<script>alert('Đã tồn tại nguồn đơn " & name & ". Bạn không thể tạo thêm được nguồn đơn này nữa')</script>")
Return
=> How to keep previos format?
This code below i using:
Private Sub grvData_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grvData.RowCommand
lblError.Text = String.Empty
Dim commandNameType As String = String.Empty
Try
If e.CommandName = "Insert" Then
commandNameType = "thêm"
Dim txtName As TextBox = DirectCast(grvData.FooterRow.FindControl("txtNewName"), TextBox)
Dim cboStatus As DropDownList = DirectCast(grvData.FooterRow.FindControl("ddlNewStatus"), DropDownList)
lblError.Text = String.Empty
Try
If String.IsNullOrEmpty(txtName.Text) Then
Return
End If
Dim pSource As New TblPetitionSource
pSource.Name = txtName.Text
pSource.Lastupdate = Now.ToString("yyyy/MM/dd HH:mm:ss")
pSource.StatusFlag = 1
pSource.UpdateBy = "ADMIN"
Dim db As New ProcuracyDataContext
Dim lst = (From p In db.TblPetitionSource Where p.Name = txtName.Text Select p).ToList()
If lst.Count > 0 Then
HttpContext.Current.Response.Write("<script>alert('Đã tồn tại nguồn đơn . Bạn không thể tạo thêm được nguồn đơn này nữa')</script>")
Return
End If
db.TblPetitionSource.InsertOnSubmit(pSource)
db.SubmitChanges()
BindData()
Catch ex As Exception
lblError.Text = ex.Message
End Try
End If
Catch ex As Exception
lblError.Text = "Lỗi không " & commandNameType & " được bản ghi này <br />" & ex.Message
End Try
End Sub
This is my code using for MergeCells:
Private Sub grvData_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvData.RowDataBound
Try
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells(e.Row.Cells.Count - 1).ColumnSpan = 2
e.Row.Cells(e.Row.Cells.Count - 1).Text = "Thao tác"
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells(e.Row.Cells.Count - 1).ColumnSpan = 4
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
Could you see more detail at these files:
https://drive.google.com/open?id=0B6NcrBkoDTV5TV9QcFFUWUpnTFk
and the form after click button:
Web form after click button
Thanks you so much!
Related
We are using following document for creating a VB.NET windows application to communicate with KepServerEx.
Title: ClientAce: Creating a Simple Windows Form Application
https://www.kepware.com/getattachment/66dac2e9-1496-4b22-9301-454e506a5ca6/clientace-simple-windows-form-application.pdf
Using the above document, we could successfully read data from KepServerEx.
However we also want to send the data inputted in VB.NET application back to the KepServerEx. Is this possible?
Solved by using following code -
"Kepware.ClientAce.OpcDaClient.DaServerMgt.Write(itemIdentifiers, OPCWriteValue)"
where -
itemIdentifiers(n)
Kepware.ClientAce.OpcDaClient.ItemIdentifier
contains tags definition
OPCWriteValue(n)
Kepware.ClientAce.OpcDaClient.ItemValue
contains tag values
Full code below:
Imports Kepware.ClientAce
Public Class Form1
Inherits System.Windows.Forms.Form
Dim maxAge As Integer = 0
Dim WithEvents daServerMgt As New Kepware.ClientAce.OpcDaClient.DaServerMgt
Dim activeClientSubscriptionHandle As Integer
Dim activeServerSubscriptionHandle As Integer
Dim itemIdentifiers(1) As Kepware.ClientAce.OpcDaClient.ItemIdentifier
Dim itemValues(1) As Kepware.ClientAce.OpcDaClient.ItemValue
Dim OPCWriteValue(1) As Kepware.ClientAce.OpcDaClient.ItemValue
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim url As String
url = "opcda://localhost/Kepware.KEPServerEX.V6"
Dim clientHandle As Integer
clientHandle = 1
Dim connectInfo As New Kepware.ClientAce.OpcDaClient.ConnectInfo
connectInfo.ClientName = "OPC UA Test Client"
connectInfo.LocalId = "en"
connectInfo.KeepAliveTime = 60000
connectInfo.RetryAfterConnectionError = True
connectInfo.RetryInitialConnection = False
Dim connectFailed As Boolean
connectFailed = False
itemIdentifiers(0) = New Kepware.ClientAce.OpcDaClient.ItemIdentifier
itemIdentifiers(0).ItemName = "Channel1.Device1.Tag1"
itemIdentifiers(0).ClientHandle = 0
itemIdentifiers(0).DataType = Type.GetType("System.Int16")
itemIdentifiers(1) = New Kepware.ClientAce.OpcDaClient.ItemIdentifier
itemIdentifiers(1).ItemName = "Channel1.Device1.Tag2"
itemIdentifiers(1).ClientHandle = 1
itemIdentifiers(1).DataType = Type.GetType("System.Int16")
Try
daServerMgt.Connect(url, clientHandle, connectInfo, connectFailed)
Catch ex As Exception
MsgBox("Handled Connect exception. Reason: " & ex.Message)
' Make sure following code knows connection failed:
connectFailed = True
End Try
Dim clientSubscriptionHandle As Integer = 1
Dim active As Boolean = True
Dim updateRate As Integer = 1000
Dim deadBand As Single = 0
Dim revisedUpdateRate As Integer
Try
daServerMgt.Subscribe(clientSubscriptionHandle, active, updateRate, revisedUpdateRate, deadBand, itemIdentifiers, activeServerSubscriptionHandle)
' Handle result:
' Save the active client subscription handle for use in
' DataChanged events:
activeClientSubscriptionHandle = clientSubscriptionHandle
' Check item result ID:
For itemIndex = 0 To 1
If itemIdentifiers(itemIndex).ResultID.Succeeded = False Then
' Show a message box if an item could not be added to subscription.
' You would probably use some other, less annoying, means to alert
' the user to failed item enrolments in an actual application.
MsgBox("Failed to add item " & itemIdentifiers(itemIndex).ItemName & " to subscription")
End If
Next
Catch ex As Exception
MsgBox("Handled Subscribe exception. Reason: " & ex.Message)
End Try
Try
daServerMgt.Read( _
maxAge, _
itemIdentifiers, _
itemValues)
' Handle results
Dim item As Integer
For item = 0 To 1
If itemIdentifiers(item).ResultID.Succeeded = True Then
Console.WriteLine( _
"Value: " & itemValues(item).Value & _
" Quality: " & itemValues(item).Quality.Name & _
" Timestamp: " & itemValues(item).TimeStamp)
Else
Console.WriteLine("Read failed for item: " & _
itemIdentifiers(item).ItemName)
End If
Next
Catch ex As Exception
Console.WriteLine("Read exception. Reason: " & ex.Message)
End Try
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
OPCWriteValue(0) = New Kepware.ClientAce.OpcDaClient.ItemValue
OPCWriteValue(0).Value = TextBox1.Text
OPCWriteValue(1) = New Kepware.ClientAce.OpcDaClient.ItemValue
OPCWriteValue(1).Value = TextBox2.Text
Try
daServerMgt.Write(itemIdentifiers, OPCWriteValue)
Catch ex As Exception
'Handle the write exception
Console.WriteLine("Sync write failed with exception " & ex.Message)
End Try
End Sub
End Class
I am having a problem with validation. I created a dynamic textboxes with corresponding dynamic numeric validator but it's not firing....
Here is my code
code behind on_load
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
For i = 0 To AssetByDimension(oVal).Rows.Count - 1
Dim lt As New Literal()
Dim label As New Label()
Dim count As Integer = pnlDimension.Controls.OfType(Of Label)().ToList().Count
label.Text = "<b>" + AssetByDimension(oVal).Rows(i)("Dimension_Type") + " (" + AssetByDimension(oVal).Rows(i)("Unit_Of_Measure_Code") + "): </b>"
pnlDimension.Controls.Add(label)
Dim textbox As New TextBox()
count = pnlDimension.Controls.OfType(Of TextBox)().ToList().Count
textbox.ID = "txtDimension" & i
pnlDimension.Controls.Add(textbox)
Dim vdr As New RegularExpressionValidator
vdr.ControlToValidate = "txtDimension" & i
vdr.ValidationExpression = "\d+"
vdr.ErrorMessage = "Numbers only"
vdr.BorderColor = Drawing.Color.Red
vdr.ForeColor = Drawing.Color.Red
vdr.SetFocusOnError = True
pnlDimension.Controls.Add(vdr)
lt.Text = "<br /><br />"
pnlDimension.Controls.Add(lt)
Next
End Sub
and here's the button event handler
Protected Sub btnSaveDim_Click(sender As Object, e As EventArgs)
if Page.isvalid then
Response.Redirect("AddAsset.aspx")
else
'do nothing...
end
End Sub
What I have tried:
I tried to use Page.isValid but is not working...
Hoping for your kind
This one is REALLY driving me nuts. I've read, and tried, most of the workarounds but still it posts back!!
All the markup is generated dynamically from code-behind and inserted into a page that is part of a Master Page, from the init event.
There are a series of nested tabs, the tab content for the most part is data in a GridView. Each Gridview is set in it's own update panel. Every time a LinkButton in the GridView is clicked there is a full postback causing the tabs to reset (any button outside of the GridView and in the UpdatePanel doesn't cause a full postback.
LinkButtons are generated like this
Dim Select_Field As New CommandField
With Select_Field
.HeaderText = "View Transactions"
.SelectText = "View Transactions"
.ShowSelectButton = True
End With
GV.Columns.Add(Select_Field)
Registering with ToolKitScriptManager
Private Sub AssessmentsMain_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim vID As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID"))
Dim LB As LinkButton = CType(e.Row.Cells(4).Controls(0), LinkButton)
LB.ID = "AssMain_" & vID
AjaxControlToolkit.ToolkitScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(LB)
End If
Catch ex As Exception
Dim vError As New SendError
vError.MailError("840", PageName, ex)
ShowError()
End Try
End Sub
and the generated markup for one row is like this
<tr class="GridView" style="color:#333333;background-color:#F7F6F3;">
<td>10</td>
<td>Adam White</td>
<td>4224 Res Road</td>
<td align="right">$6,850.65</td>
<td>
<a id="ctl00_ContentPlaceHolder1_AssessmentsMainGV_ctl02_AssMain_10" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$AssessmentsMainGV','Select$0')" style="color:#333333;">View Transactions</a>
The GridView class
Public Class HAS_Gridview
Inherits GridView
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
CellPadding = 4
GridLines = WebControls.GridLines.None
ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
ClientIDMode = UI.ClientIDMode.AutoID
With MyBase.FooterStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Color.White
End With
RowStyle.BackColor = Drawing.ColorTranslator.FromHtml("#F7F6F3")
RowStyle.ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
PagerStyle.HorizontalAlign = WebControls.HorizontalAlign.Center
PagerStyle.ForeColor = Color.Black
PagerStyle.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
With MyBase.SelectedRowStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
End With
With MyBase.HeaderStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Color.Black
.CssClass = "GridView"
End With
EditRowStyle.BackColor = Drawing.ColorTranslator.FromHtml("#999999")
With MyBase.AlternatingRowStyle
.BackColor = Color.White
.ForeColor = Drawing.ColorTranslator.FromHtml("#284775")
.CssClass = "GridView"
End With
With MyBase.RowStyle
.CssClass = "GridView"
End With
End Sub
End Class
Have you tried adding trigger programmatically instead of registering in AjaxControlToolkit:
Dim trigger As New AsyncPostBackTrigger()
trigger.ControlID = LB.ID
trigger.EventName = "Click"
MyUpdatePanel.Triggers.Add(trigger)
It looks like the postback is caused by href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$AssessmentsMainGV','Select$0')" in the generated markup for the anchor tag.
Try to define your own _doPostBack.
If you haven't checked post a and post b already, they offer a couple of ways to do that.
In the end the only way I could get this to work was
Create a class for a LinkButton Template
Public Class LinkButtonTemplate
Implements ITemplate
Private m_ColumnName As String
Event LinkButtonItem_Clicked(sender As LinkButton, e As EventArgs)
Public Property ColumnName() As String
Get
Return m_ColumnName
End Get
Set(ByVal value As String)
m_ColumnName = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal ColumnName As String)
Me.ColumnName = ColumnName
End Sub
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim LB As New LinkButton()
With LB
.ID = "LB_" & ColumnName
.Text = ColumnName
.OnClientClick = "LinkButtonClick(this);"
End With
container.Controls.Add(LB)
End Sub
End Class
Add this javascript so that it would post the ID to a hidden field and click a hidden button
Private Sub LoadLinkButtonClick()
Try
Dim SB As New StringBuilder
SB.Append("function LinkButtonClick(LinkButton){ ")
SB.Append("setTimeout(function() { ")
SB.Append("$get('" & GridViewLBClicked.ClientID & "').click(); ")
SB.Append(" }, 300); ")
SB.Append("var sendingID = LinkButton.id; ")
SB.Append("document.getElementById('" & HiddenField1.ClientID & "').value = sendingID; ")
SB.Append("} ")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "LoadLinkButton", SB.ToString, True)
Catch ex As Exception
Dim vError As New SendError
vError.MailError("1229", PageName, ex)
End Try
End Sub
On the RowDataBound event capture the ID we need and add it to the LinkButton ID (so now we know both the sending GridView and the selected row)
Private Sub AssessmentsMain_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim vID As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID"))
Dim LB As LinkButton = CType(e.Row.Cells(4).Controls(0), LinkButton)
LB.ID = "AssMain_" & vID
End If
Catch ex As Exception
Dim vError As New SendError
vError.MailError("840", PageName, ex)
ShowError()
End Try
End Sub
From the hidden button click we can recover all the data we need to make the async postback
Private Sub RaiseLinkButton_Click(sender As Object, e As EventArgs)
Try
Dim vFunction As New Functions
Dim vValue As String = HiddenField1.Value
Dim vSplit = vValue.Split("_")
Dim i As Integer = 0
For Count As Integer = 0 To vSplit.Length - 1
i += 1
Next
Dim DGName As String = vSplit(i - 2)
Select Case DGName
Case "AssMain"
Dim MV As MultiView = vFunction.FindControlRecursive(BodyMain, "AssessmentMultiView")
Dim GV As CustomControl.HAS_Gridview = vFunction.FindControlRecursive(BodyMain, "AssessmentDetailGV")
With GV
.DataSource = AssessmentsDetail_ReturnDataSet()
.DataBind()
.PageIndex = 0
End With
MV.ActiveViewIndex = 1
Dim vPanel As UpdatePanel = vFunction.FindControlRecursive(BodyMain, "AssessmentUpdatePanel")
vPanel.Update()
End Select
Catch ex As Exception
Dim vError As New SendError
vError.MailError("953", PageName, ex)
ShowError()
End Try
End Sub
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"
This code will display selected checkboxes Text in textbox as in the order i checked it 1,2,3,4,5,6,7,8,9
But it will not display selected checkboxes Text in textbox after 9
Partial Class _45seater_WebUserControl
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim str As String = Nothing
Dim id As String = Nothing
Dim ch As String = Nothing
For Each ctrl As Control In Panel1.Controls
If ctrl.GetType() Is GetType(CheckBox) Then
Dim chk As CheckBox = ctrl
UpdatePanel1.FindControl("chk")
If chk.Checked = True Then
If TextBox1.Text = "" Then
TextBox1.Text = chk.Text
Else
Dim SearchString As String = chk.Text
id = TextBox1.Text
If id.Contains(SearchString) <> -1 Then
TextBox1.Text = TextBox1.Text + "," + chk.Text
Else
End If
End If
Else
Dim SearchString As String = chk.Text
id = TextBox1.Text
If id.Contains(SearchString) <> -1 Then
Else
id = RemoveSubString(id, chk.Text)
TextBox1.Text = id
End If
End If
End If
Next
End Sub
Private Function RemoveSubString(ByVal stringvalue As String, ByVal stringremove As String) As String
Dim pos As Integer = stringvalue.IndexOf(stringremove)
If pos > 0 Then
Return stringvalue.Remove(pos - 1, stringremove.Length + 1)
ElseIf pos = 0 Then
If stringvalue.Contains(",") <> -1 Then
Return stringvalue.Remove(pos, stringremove.Length)
Else
Return stringvalue.Remove(pos, stringremove.Length + 1)
End If
End If
Return stringvalue
End Function
End Class
can any body show after chekbox10,checkbox11,checkbox12 in text box as 10,11,12 ......so on using this code
I really don't understand that requirement but i think the only thing the function should do is to print the ID's of all checked CheckBoxes in a TextBox.
Why do you complicated it, this works too:
TextBox1.Text = String.Empty
For Each control As Control In form1.Controls
If TypeOf control Is CheckBox AndAlso DirectCast(control, CheckBox).Checked Then
TextBox1.Text &= control.ID & ","
End If
Next
'remove last comma'
If TextBox1.Text.Length <> 0 Then TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
According to your new informations about the order, try this:
Protected Sub CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim separator As Char = ","c
If TextBox1.Text.Length <> 0 Then
Dim allIIDs As New List(Of String)(TextBox1.Text.Split(separator))
allIIDs.Remove(chk.ID)
If chk.Checked Then
allIIDs.Add(chk.ID)
End If
TextBox1.Text = String.Empty
For Each id As String In allIIDs
TextBox1.Text &= id & separator
Next
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
Else
TextBox1.Text = chk.ID
End If
End Sub
To register the CheckedChanged-Event on the CheckBoxes you have to add following on aspx for every Checkbox:
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckedChanged" />
or if you are lazy and want to do that in Codebehind, add following in Page_Init:
Private Sub WebForm1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
For Each control As Control In Me.form1.Controls
If TypeOf control Is CheckBox Then
Dim chk As CheckBox = DirectCast(control, CheckBox)
chk.AutoPostBack = True
AddHandler chk.CheckedChanged, AddressOf CheckedChanged
End If
Next
End Sub