You must Sign In to post a response.
Category: ASP.NET
#767162
messagebox class will not work in asp.net as it run on server. you need to use TRY .. CATCH to show and handle messages
Put a label on form named 'errorLabel' and when you does not get any record then you can throw exception from program and show error message on label as below
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
Put a label on form named 'errorLabel' and when you does not get any record then you can throw exception from program and show error message on label as below
Try
Dim Date = txtDate.Text
Dim pdf As Byte()
Dim ID As String
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT Id, BinaryData FROM dbo.Reports WHERE date=@Date "
cmd.Parameters.AddWithValue("@Date ", Date)
cmd.Connection = con
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
if sdr.hasrows then
sdr.Read()
pdf = DirectCast(sdr("BinaryData"), Byte())
ID = sdr("RunId").ToString()
else
//messagebox("records not found")
Throw new Exception("records not found")
end if
End Using
con.Close()
End Using
End Using
Response.Clear()
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", Convert.ToString("attachment; filename=Report.pdf"))
Response.BufferOutput = True
'Response.AddHeader("Content-Length", Response.Length.ToString())
Response.BinaryWrite(pdf)
Response.[End]()
Catch ex As Exception
labelError.Text = ex.Message
End Try
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
#767164
Hi,
messagebox will work in windows applications, in web applications you can handle it in no of ways using dialog box you can show the message what ever you want and using label you can show it but the thing is how you are customized that is more important.
Hope this will helpful to you...
--------------------------------------------------------------------------------
Give respect to your work, Instead of trying to impress your boss.
N@veen
Blog : http://naveens-dotnet.blogspot.in/
messagebox will work in windows applications, in web applications you can handle it in no of ways using dialog box you can show the message what ever you want and using label you can show it but the thing is how you are customized that is more important.
if(condition)
{
//record found case
}
else
{
string message = "Record not found..";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
Hope this will helpful to you...
--------------------------------------------------------------------------------
Give respect to your work, Instead of trying to impress your boss.
N@veen
Blog : http://naveens-dotnet.blogspot.in/
#767168
Hi,
Use Page.ClientScript.RegisterStartupScript as follows to call JavaScript Alert() function through code behind :
Use Page.ClientScript.RegisterStartupScript as follows to call JavaScript Alert() function through code behind :
if sdr.hasrows then
sdr.Read()
pdf = DirectCast(sdr("BinaryData"), Byte())
ID = sdr("RunId").ToString()
else
Page.ClientScript.RegisterStartupScript(Me.GetType(), "Window", "alert('records not found');", True)
end if
Return to Return to Discussion Forum