I have been using label text to show different status in an asp.net website.
e.g. "Profile Updates", "Invalid Character" etc, however would prefer to have a pop up message box instead.
This is what I have tried -
string alert = ws.webMethod(TextBox1.Text);
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>");
However when this is fired, the screen in IE just seems to get bigger, and no message box is presented.
How can I achieve this?
I would not advise doing this, it looks like you are creating a modal dialog on page load, meaning that your page cannot continue processing until a user has clicked OK.
That said, however, your problem is probably a lack of quotes around the alerted text:
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + alert + "')</SCRIPT>");
Use ClientScriptManager.RegisterClientScriptBlock instead of Response.Write
string alert = ws.webMethod(TextBox1.Text);
string script = "<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>"
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlockName", script );
I have used this in my project, works fine for me
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('message')", true);
you can use alert or you can use jquery plugin like this and this.
if use jquery plugin you can custom message box like change backColor or...
Related
I am developing a website in which I am trying to display messages through ClientScript.RegisterStartUpScript.
This one was displayed successfully:
ClientScript.RegisterStartupScript(this.GetType(), "myalert",
"alert('All questions have been visited !');", true);
Although it gave a message with a checkbox saying "Prevent this page from creating additional dialogs".I did not check the checkbox. In my code behind I have this condition:
if (lblUnConfirmedQuestions.Text=="0")
{
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "msg",
"alert( 'Please attempt all the questions !')",true);
}
This one was supposed to be displayed later but it did not appear.
On the internet I found a suggestion to remove single quotes from the ClientScript message ,I removed them but still no success could be achieved.What should I do to display the second clientscript message?
"Please attempt all the questions !" is just text.
You need something like this in order to display alert message.
ClientScript.RegisterStartupScript(this.GetType(),
"msg", "alert('Please attempt all the questions !');",true);
I am working on asp.net web application.
I have one UpdatePanel and there is table inside table which has data in some TextBoxes.
I have one save button too inside this UpdatePanel
So I want to save this data into Database, when I click Save Button.
This is working fine till now.
But I want to show alert message to User that information saved successfully. I'm using javascript for this purpose, But Javascript is not working.
so is this possible to achieve the desired functionality using javascript, if yes then please guide me Or if there is any other alternative method except this please let me know.
Thanks,
Vivek
If you have update panel use ScriptManager.RegisterClientScriptBlock as below
ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true)
Remember that you can't use Response.Write during an asynchronous postback.
It would be good if you have posted your code here.
Try This Line of Code
Its Definitely work with Update panel.
var message = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize("Bill No. : " + BillNo + " successfully generated.");
var script = string.Format("alert({0});window.location ='ChhallanPrint.aspx';", message);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", script, true);
Try this for popup sweetalert in asp vb.net
Dim message As String = " swal('Added!','Country Added Successfully.', 'success')"
ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "sweetAlert", message, True)
string message = " swal('"+gelen[2]+"!','Sepete Eklendi.', 'success')";
ScriptManager.RegisterClientScriptBlock(this,this.GetType(), "sweetAlert", message, true);
I am using the ClientScript.registerstartup for a conformation message.when the data get saved,it shows a popup as the data has been saved sucessfully.But in that pop up,in the header it shows my localweb address as "The page at ** /localhost:58562/says** and below this it shows the messgae.But i need to change this header text.Is it possible to do it..??? or any other ways to do so..??
ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('This Department Name already exist')", true);
This the code.
Thanks.
** "
Simply have a modal popup extender control with dummy target control id and call the modalpopup.Show() method where you want to show the alert.
Design the panel with header style and have your own text.
No you can't.
Its a security/anti-phishing feature.
Instead you can make your own version of alert and it will do what you want. A simple modal and override the alert function call.
You can use Jquery to have your own alert boxes or confirm boxes. There are many ways but you can use this one. or this or this
Cheers!!!
String message = "Are you sure the event: \"" + event_text + "\" has been complete for Loan# " + loannumber + "?"; //show popup to confirm the completion of event
var result = System.Windows.Forms.MessageBox.Show(message, "Loan # "+loannumber+" - Processed Event: "+event_text, System.Windows.Forms.MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.No)
{
//do nothing close popup
}
else
{
//do something else
I have this code behind on my ASP.NET page. When I click a button on my webpage, this popup should show up. The problem is that sometimes it shows up in the foreground, but sometimes I have to actually click on the little icon on the doc.
Any ideas?
It is unusual to show a server side dialog as part of a web application. That will block the thread for the web server, and the user (unless they are sitting at the web server console, rather than in their home/office with a web browser) won't see it.
I think you want to do a client side popup - perhaps with a javascript Alert or a HTML dialog box.
Do not use a MessageBox.
If you need to fire a JavaScript alert message from the code-behind, try using the ScriptManager.
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "clientScript", "alert('hi');", true)
The code above uses the page to register the script and fire off the alert message. The final parameter true, indicates the the tags will open and close around the script you provided.
I have the following message box in c# on my asp.net page inside the btnSubmit_Click event.
It tends to popup sometimes and not popup sometimes. Any reasons as to why it is not consistent?
ClientScript.RegisterStartupScript(
GetType(),
"alert",
"alert('An email has been sent to Customer Service');",
true);
I guess that this will depend on the text you are putting inside the alert. In the example you provided the text is hardcoded but I suppose that in your real application this text is dynamic and might contain characters that break javascript such as '. Try using FireBug to see if there are some javascript errors when it doesn't work.
Have You checked, if the alert('An email has been sent to Customer Service'); line is in the HTML Source after you clicked the Button and the message did NOT appear?
If it isn't in the HTML, check:
with the Debugger if your
codeblock is hit
are you maybe redirecting the response?
try these popups instead
type java directly in the visualstudio GUI
On a button go to the "OnClientClick" property (its not into events*) over there type:
return confirm('are you sure?')
it will put a dialog with cancel ok buttons transparent over current page if cancel is pressed no postback will ocure. However if you want only ok button type:
alert ('i told you so')
The events like onclick work server side they execute your code, while OnClientClick runs in the browser side. the come most close to a basic dialog
as this codes is so small it should work unless they have really strange browser clients