[关闭]错误未在警告框中显示:-( [英] [Closed]Error is not displayed in alert box :-(

查看:64
本文介绍了[关闭]错误未在警告框中显示:-(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试

在警报框中显示"importsites不是一个有效的名称...."错误,当上载的excel文件具有错误的选项卡名称,但是不显示时,它会掉线.

如果文件格式错误,则显示警告框,但如果选项卡名称不同,则不会显示

非常感谢所有帮助:-)

Hi
I am trying to get

"importsites is not a valid name...." error to display in the alert box, when the excel file that is uploaded has the incorrect tab name, however it does not display, it just falls through.

An alert box is displayed if the file is in the wrong format but not if the tab name is different

all help is much appreciated :-)

importButtonEnabled = True
      PanelUpload.Visible = False
      PanelView.Visible = True
      PanelImport.Visible = False
      btnBack.Visible = True
      btnBack.Enabled = True

      Dim xConnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & Server.MapPath("SiteTemplate.xls") & ";" & _
                        "Extended Properties=Excel 8.0"
      Dim objXConn As New System.Data.OleDb.OleDbConnection(xConnstr)

      Try
          objXConn.Open()

          Dim objCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM [importsites$]", objXConn)

          'On Error Resume Next
          'objXConn.Close()

          Dim objDataAdapter As New OleDbDataAdapter()

          'If objCommand Is Nothing Then

          'Else

          objDataAdapter.SelectCommand = objCommand

          Dim objDataSet As New DataSet()
          objDataAdapter.Fill(objDataSet, "xldata")

          'view the data you have uploaded in your gridview. this will check for any empty rows at this point and change the colours if necessary
          GridView1.DataSource = objDataSet.Tables(0).DefaultView
          GridView1.DataBind()
          'End If
          objXConn.Close()

          ButtonImport.Enabled = importButtonEnabled
          If ButtonImport.Enabled = False Then
              lblerror.ForeColor = System.Drawing.Color.Red
              lblerror.Text = "ERROR WITH FILE"
          End If

      Catch ex As Exception
          Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">")
          Response.Write("alert('" & ex.Message.ToString & "')")
          Response.Write("</script>")

          If objXConn.State = ConnectionState.Open Then
              objXConn.Close()

          End If

      End Try

  End Sub

推荐答案

",objXConn) ' 错误恢复下一个 ' objXConn.Close() Dim objDataAdapter As 新建 OleDbDataAdapter() ' 如果objCommand什么都没有, ' 其他 objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet() objDataAdapter.Fill(objDataSet," ) ' 查看您在gridview中上传的数据.这将检查此时是否有空行,并在必要时更改颜色 GridView1.DataSource = objDataSet.Tables( 0 ).DefaultView GridView1.DataBind() ' 如果结束 objXConn.Close() ButtonImport.Enabled = importButtonEnabled 如果 ButtonImport.Enabled = 错误 然后 lblerror.ForeColor = System.Drawing.Color.Red lblerror.Text = " 结束 如果 捕获,例如 As 异常 Response.Write(" ) Response.Write(" & ex.Message.ToString& " ) Response.Write(" ) 如果 objXConn.State = ConnectionState.打开然后 objXConn.Close() 结束 如果 结束 尝试 结束
", objXConn) 'On Error Resume Next 'objXConn.Close() Dim objDataAdapter As New OleDbDataAdapter() 'If objCommand Is Nothing Then 'Else objDataAdapter.SelectCommand = objCommand Dim objDataSet As New DataSet() objDataAdapter.Fill(objDataSet, "xldata") 'view the data you have uploaded in your gridview. this will check for any empty rows at this point and change the colours if necessary GridView1.DataSource = objDataSet.Tables(0).DefaultView GridView1.DataBind() 'End If objXConn.Close() ButtonImport.Enabled = importButtonEnabled If ButtonImport.Enabled = False Then lblerror.ForeColor = System.Drawing.Color.Red lblerror.Text = "ERROR WITH FILE" End If Catch ex As Exception Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">") Response.Write("alert('" & ex.Message.ToString & "')") Response.Write("</script>") If objXConn.State = ConnectionState.Open Then objXConn.Close() End If End Try End Sub


看看RegisterStartupScript方法
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx [ ^ ]
Have a look at the RegisterStartupScript method
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx[^]



我的队友找到了解决方案,并且我可以相信:-(我花了2天的时间来维护Serachin,原因是捕获的错误中有一个单引号",将其排除在外,所以解决方案如下

hi
my team mate found the solution and i can believe it :-( i have spent 2 days serachin for a reason and the issue was that there was a single quote '' in the caught error which was kicking it out so the solution was the following

Response.Write("<script LANGUAGE=JavaScript type=""text/javascript"">")
            Response.Write("alert('" & ex.Message.ToString.Replace("'", """") & "')")
            Response.Write("</script>")




感谢所有张贴tho:-)




thanks for everyone who posted tho :-)


这篇关于[关闭]错误未在警告框中显示:-(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆