Alert message script
-
I wanted to give alert message when the search result is invalid.... I have a code but its not working. Could anyone help me?
protected void btn_search_Click(object sender, EventArgs e)
{
lstbox_clotho.Items.Clear();
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")
{
string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories);
foreach (string file in licfiles)
{
lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file));
}{ txtbox\_clotho.Text = ""; }
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}} }
-
I wanted to give alert message when the search result is invalid.... I have a code but its not working. Could anyone help me?
protected void btn_search_Click(object sender, EventArgs e)
{
lstbox_clotho.Items.Clear();
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")
{
string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories);
foreach (string file in licfiles)
{
lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file));
}{ txtbox\_clotho.Text = ""; }
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}} }
You must be more specific than, "it's not working." What is it doing wrong? Is there an error message? If yes, what's the message and on what line of code does it happen?
The difficult we do right away... ...the impossible takes slightly longer.
-
You must be more specific than, "it's not working." What is it doing wrong? Is there an error message? If yes, what's the message and on what line of code does it happen?
The difficult we do right away... ...the impossible takes slightly longer.
There is no error. It is not showing any messages..
-
There is no error. It is not showing any messages..
Show the entire HTML document as it is passed to the client. You do know that you can't just send that script snippet as the whole document, right?
The difficult we do right away... ...the impossible takes slightly longer.
-
Show the entire HTML document as it is passed to the client. You do know that you can't just send that script snippet as the whole document, right?
The difficult we do right away... ...the impossible takes slightly longer.
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections; namespace wsmfgit { /// <display files in listbox from directory> public partial class downloadsoftware : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Directory.CreateDirectory("C:\\DesktopCopyTemp"); DirectoryInfo info = new DirectoryInfo(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\DesktopCopyTemp"); FileInfo[] Files = info.GetFiles("*.*"); foreach (FileInfo file in Files) { ListBox1.Items.Add(file.Name); } } ///</display> /// <link to home button> protected void imgbtn_home_Click(object sender, ImageClickEventArgs e) { Response.Redirect("default.aspx"); } ///</link> ///<software download button1> protected void btn_dwn_Click(object sender, EventArgs e) { string File = ListBox1.SelectedValue; Response.ContentType = ContentType; Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(File)); Response.End(); } /// </software> protected void btn_search_Click(object sender, EventArgs e) { lstbox_clotho.Items.Clear(); string search=txtbox_clotho.Text; if (txtbox_clotho.Text != "") { string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories); foreach (string file in licfiles) { lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file)); } { txtbox_clotho.Text = ""; } } } protected void imgbtn_dwn_Click(object sender, ImageClickEventArgs e) { string licfiles = lstbox_clotho.SelectedValue; Response.ContentType = ContentType; Response.AppendHeader("Content-Disposition", "attachmen
-
I wanted to give alert message when the search result is invalid.... I have a code but its not working. Could anyone help me?
protected void btn_search_Click(object sender, EventArgs e)
{
lstbox_clotho.Items.Clear();
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")
{
string[] licfiles = Directory.GetFiles(@"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\Clotho_License", "*" + txtbox_clotho.Text + "*.lic", SearchOption.AllDirectories);
foreach (string file in licfiles)
{
lstbox_clotho.Items.Add(new ListItem(Path.GetFileName(file), file));
}{ txtbox\_clotho.Text = ""; }
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}} }
Many problems! Let me dissect and show them to you: First of all, why did you create a variable to hold the text, when you are again going to use the same object's Text property?
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")Either remove the variable, or use the variable here. Tip: Remove the variable. Secondly, if you have a look at the block where your alert-dialog's code is present?
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}How would you expected it execute when your condition is so wrong? "
if (txtbox_clotho.Text != "")
". The condition tells that the script would only be written, if the search term is empty; not invalid. Also, it doesn't work with the search result, it is applied to the search term (if I understand correctly). Solution to this is, to re-write the code. Who wrote the code, so back? Where he was creating extra scopes (inside the if block), writing an entirely opposite condition and implement a very bad design, writing the script based on aResponse.Write
is always recommended not to be done. The code seriously needs some rewriting. Explain the scenario, we can help you put some effort in it. :-)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
Many problems! Let me dissect and show them to you: First of all, why did you create a variable to hold the text, when you are again going to use the same object's Text property?
string search=txtbox_clotho.Text;
if (txtbox_clotho.Text != "")Either remove the variable, or use the variable here. Tip: Remove the variable. Secondly, if you have a look at the block where your alert-dialog's code is present?
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}How would you expected it execute when your condition is so wrong? "
if (txtbox_clotho.Text != "")
". The condition tells that the script would only be written, if the search term is empty; not invalid. Also, it doesn't work with the search result, it is applied to the search term (if I understand correctly). Solution to this is, to re-write the code. Who wrote the code, so back? Where he was creating extra scopes (inside the if block), writing an entirely opposite condition and implement a very bad design, writing the script based on aResponse.Write
is always recommended not to be done. The code seriously needs some rewriting. Explain the scenario, we can help you put some effort in it. :-)The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
Thank you for kind sharing. I wanted to display files from server to list box. I also wanted to put search button to search the files. the search button must be search from all directories or subfolders. if the file not exist in the server it must show an alert message. Now, my problem is I do not know how to show alert message in c#...Could you pls help... asp.net code:
<asp:TextBox ID="txtbox_clotho" placeholder="Search by Mac Address" runat="server" Height="21px" style="margin-left: 45px" Width="217px" BorderColor="#333333" BorderStyle="Solid" ></asp:TextBox>
<br />
<asp:Button ID="btn_search" runat="server" BackColor="#006699" BorderColor="Black" BorderStyle="Groove" Font-Bold="True" Font-Size="Medium" ForeColor="White" OnClick="btn_search_Click" style="z-index: 1; left: 279px; top: 58px; position: absolute; height: 30px; width: 74px" Text="Search" />
<br />
<br />
<asp:ListBox ID="lstbox_clotho" runat="server" Height="81px" style="margin-left: 47px" Width="245px" ></asp:ListBox>
<asp:ImageButton ID="imgbtn_dwn" runat="server" ImageUrl="~/images/download.png" Height="49px" Width="50px" OnClick="imgbtn_dwn_Click" />
<br />c# code:
<pre lang="cs">using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;namespace wsmfgit
{/// <display files in listbox from directory> public partial class downloadsoftware : System.Web.UI.Page { protected void Page\_Load(object sender, EventArgs e) { DirectoryInfo info = new DirectoryInfo(@"\\\\192.168.5.10\\fbar\\TOOLS\\ProbingApps\\ProbingSystem\\DesktopCopyTemp"); FileInfo\[\] Files = info.GetFiles("\*.\*"); foreach (FileInfo file in Files) { ListBox1.Items.Add(file.Name); } } ///</display> /// <link to home button&
-
Thank you for kind sharing. I wanted to display files from server to list box. I also wanted to put search button to search the files. the search button must be search from all directories or subfolders. if the file not exist in the server it must show an alert message. Now, my problem is I do not know how to show alert message in c#...Could you pls help... asp.net code:
<asp:TextBox ID="txtbox_clotho" placeholder="Search by Mac Address" runat="server" Height="21px" style="margin-left: 45px" Width="217px" BorderColor="#333333" BorderStyle="Solid" ></asp:TextBox>
<br />
<asp:Button ID="btn_search" runat="server" BackColor="#006699" BorderColor="Black" BorderStyle="Groove" Font-Bold="True" Font-Size="Medium" ForeColor="White" OnClick="btn_search_Click" style="z-index: 1; left: 279px; top: 58px; position: absolute; height: 30px; width: 74px" Text="Search" />
<br />
<br />
<asp:ListBox ID="lstbox_clotho" runat="server" Height="81px" style="margin-left: 47px" Width="245px" ></asp:ListBox>
<asp:ImageButton ID="imgbtn_dwn" runat="server" ImageUrl="~/images/download.png" Height="49px" Width="50px" OnClick="imgbtn_dwn_Click" />
<br />c# code:
<pre lang="cs">using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;namespace wsmfgit
{/// <display files in listbox from directory> public partial class downloadsoftware : System.Web.UI.Page { protected void Page\_Load(object sender, EventArgs e) { DirectoryInfo info = new DirectoryInfo(@"\\\\192.168.5.10\\fbar\\TOOLS\\ProbingApps\\ProbingSystem\\DesktopCopyTemp"); FileInfo\[\] Files = info.GetFiles("\*.\*"); foreach (FileInfo file in Files) { ListBox1.Items.Add(file.Name); } } ///</display> /// <link to home button&
Only the language being used is C#, the framework that you are using is ASP.NET Web Forms. So, consider looking for an answer in ASP.NET Web Forms framework, not C#. In C# there are many ways to show a dialog,
// .NET
new MessageBox("Hello").Show();// Windows Runtime
new MessageDialog("Hello").ShowAsync();// etc
The one you are looking for is ASP.NET based, which is for sure,
alert('hello')
. The thing is that you are sending the alert box to the client, do not do this. Alerts must be shown once the page has been loaded, in case if there is an error. Do not show a popup as soon as the page loads. Try this: 1. Send an ajax request to the web page, to find the files. 2. Send a response, if that response fails - Show the alert box. This way you will implement what you want, it would allow you to use plain-JavaScript to do this.The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~