Click to See Complete Forum and Search --> : To Display a message from within a aspx.cs page
akshatha306
May 25th, 2006, 08:07 AM
hi everyone
when i click a button ,I have to check for a condition. if the condition is false i want to display a message with an ok and cancel button. And i want to return true or false values respectively.how can i do this...
and one more thing how do i call a javascript function from within a aspx.cs file....
however knows the solution for this just let me know. thank you...
akshatha
Shuja Ali
May 25th, 2006, 08:17 AM
Welcome to the Forum. :wave:
This has been discussed in the forum earlier too.
Take a look at these threads
http://www.codeguru.com/forum/showthread.php?t=382801&highlight=Javascript
http://www.codeguru.com/forum/showthread.php?t=380821&highlight=Javascript
akshatha306
May 26th, 2006, 01:40 AM
But i want to call a javascript from a aspx.cs file to display a message box like "do u really wan to add a row"...
depending on the value i want to do some operations.
Shuja Ali
May 26th, 2006, 06:18 AM
But i want to call a javascript from a aspx.cs file to display a message box like "do u really wan to add a row"...
depending on the value i want to do some operations.
You will have to use confirm function of the Javascript. In the Page Load event register this script Button1.Attributes.Add("onclick","if(confirm('Are you sure you want to Add?')){}else{return false}"); NOw if the user selects Ok it will postback the page and if the user selects cancel it will not do anything.
Is this what you are looking for?
akshatha306
May 26th, 2006, 07:27 AM
Thanks shuja ali. i will try that out.
akshatha306
June 2nd, 2006, 08:55 AM
i have the procedure to be called if ,confirm OK. That procedure is in the aspx.cs file.
i tried calling it in the if loop. but that doesnt work. how do i call the procedure..
can we call an procedure in aspx.cs file from a java script.
Shuja Ali
June 5th, 2006, 03:09 AM
Can you explain a bit more as to what exactly you are trying to do? I am not able to understand the problem here.
akshatha306
June 6th, 2006, 02:29 AM
I have a grid created using Infragistics(tool to create a grid) in my aspx file.
There is a button to delete the selected row in a grid.. i have written an server side code for deleting a row.
so what i want is when i click on the delete Row button a message is to be displayed saying. "Are you sure you want to delete" If OK then i want to call that method in the aspx.cs file to delete that row..
My question is, can we call a method defined in the .cs file from the javaScript . i tried doing it.. i didnt get the result . how can i do it..
Shuja Ali
June 6th, 2006, 02:44 AM
The code in post #4 does exactly the same thing. Have you tried that code?
You just need to write the code in the PageLoad event. Thats all you have to do. There is no need to call anything from anywhere.
The code posted in that post will add a client side script to the HTML page and then when the button is clicked the client side script will get executed first. If the user clicks ok then the server side code of the same button will get executed.
akshatha306
June 8th, 2006, 05:30 AM
Thanks Shuja..
its working now. last time i tried there was some problem with my button click event because of which it didnt work..
its ok now...
akshatha306
June 9th, 2006, 01:03 AM
Hi There is small change in the requirement...
The problem is: When i click on the deleteRow button it should check if the row is selected. or else alert the user saying "please select a row" and get back to the page without any operations...
If however a row is selected then ask for the confirmation. if OK then go ahead and delete the button.
I cant do this in the pageload cos it takes the previous value for row selected.
Right Now what i am doing is: in the button click event i have written the following code snippet:
int select=dgClaimInfo.DisplayLayout.SelectedRows.Count;
if(select==0)
{
Response.Write("<script>alert('hi');</script>");
}
else
{
Response.Write("<script>if(confirm('Are You SURE')){} else { return false; }</script>");
dgClaimInfo.DisplayLayout.ActiveRow.Delete();
}
The alert part is ok. but on confirm whether it is ok or cancel it is deleting the row in the grid. i dont want it to delete when cancel is clicked.
how can i do it.is there any other way of doing it without using Response.write
Please let me know
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.