473,774 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help needed calling C# method from javascript

I would like to be able to call methodTrue() when the user clicks yes and
methodFalse() when they click No. How do i accomplish that? here is my code:

private void methodTrue()
{
//method false details
}
private void methodFalse()
{
//method false details
}
public void CreateMessagePr om2(System.Web. UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>");
sb.Append("var results = window.confirm( '" + strMessage + "');");
sb.Append("if (results == true)");
sb.Append("{ alert('The value is true');}"); //call methodTrue
sb.Append("else ");
sb.Append("{ alert('the value is false');}"); //call methodFalse

sb.Append("</script>");

string strScript = sb.ToString();

if (!aspxPage.IsSt artupScriptRegi stered(strKeyPr ompt))
{
aspxPage.Regist erStartupScript (strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.To String();
}
}
Nov 19 '05 #1
4 1505
You cannot achieve this without a postback. Assign a value, true or false,
to a hidden textbox and submit the form with your javascript. Then check
the textbox for a true or false value in your page_load and call the
appropriate method.

Shawn

"Mori" <Mo**@discussio ns.microsoft.co m> wrote in message
news:50******** *************** ***********@mic rosoft.com...
I would like to be able to call methodTrue() when the user clicks yes and
methodFalse() when they click No. How do i accomplish that? here is my code:
private void methodTrue()
{
//method false details
}
private void methodFalse()
{
//method false details
}
public void CreateMessagePr om2(System.Web. UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>");
sb.Append("var results = window.confirm( '" + strMessage + "');");
sb.Append("if (results == true)");
sb.Append("{ alert('The value is true');}"); //call methodTrue
sb.Append("else ");
sb.Append("{ alert('the value is false');}"); //call methodFalse

sb.Append("</script>");

string strScript = sb.ToString();

if (!aspxPage.IsSt artupScriptRegi stered(strKeyPr ompt))
{
aspxPage.Regist erStartupScript (strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.To String();
}
}

Nov 19 '05 #2
The user clicks buttons on his user machine. The c# methods belong to your
asp.net application that runs on your web server. You should make the
buttons to server controls and call methodTrue and methodFalse in the
serve-side onclick event handlers. To add client-side confirm functionality
you need to add client-side onclick event handlers:

YesButton.Attri butes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmYes);
NoButton.Attrib utes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussio ns.microsoft.co m> wrote in message
news:50******** *************** ***********@mic rosoft.com...
I would like to be able to call methodTrue() when the user clicks yes and
methodFalse() when they click No. How do i accomplish that? here is my code:
private void methodTrue()
{
//method false details
}
private void methodFalse()
{
//method false details
}
public void CreateMessagePr om2(System.Web. UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>");
sb.Append("var results = window.confirm( '" + strMessage + "');");
sb.Append("if (results == true)");
sb.Append("{ alert('The value is true');}"); //call methodTrue
sb.Append("else ");
sb.Append("{ alert('the value is false');}"); //call methodFalse

sb.Append("</script>");

string strScript = sb.ToString();

if (!aspxPage.IsSt artupScriptRegi stered(strKeyPr ompt))
{
aspxPage.Regist erStartupScript (strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.To String();
}
}

Nov 19 '05 #3
There really are no buttons other than the ones that come with the
window.confirm script

"Eliyahu Goldin" wrote:
The user clicks buttons on his user machine. The c# methods belong to your
asp.net application that runs on your web server. You should make the
buttons to server controls and call methodTrue and methodFalse in the
serve-side onclick event handlers. To add client-side confirm functionality
you need to add client-side onclick event handlers:

YesButton.Attri butes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmYes);
NoButton.Attrib utes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussio ns.microsoft.co m> wrote in message
news:50******** *************** ***********@mic rosoft.com...
I would like to be able to call methodTrue() when the user clicks yes and
methodFalse() when they click No. How do i accomplish that? here is my

code:

private void methodTrue()
{
//method false details
}
private void methodFalse()
{
//method false details
}
public void CreateMessagePr om2(System.Web. UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>");
sb.Append("var results = window.confirm( '" + strMessage + "');");
sb.Append("if (results == true)");
sb.Append("{ alert('The value is true');}"); //call methodTrue
sb.Append("else ");
sb.Append("{ alert('the value is false');}"); //call methodFalse

sb.Append("</script>");

string strScript = sb.ToString();

if (!aspxPage.IsSt artupScriptRegi stered(strKeyPr ompt))
{
aspxPage.Regist erStartupScript (strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.To String();
}
}


Nov 19 '05 #4
Ok, then go for the hidden textbox as the other poster has suggested.

Eliyahu

"Mori" <Mo**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
There really are no buttons other than the ones that come with the
window.confirm script

"Eliyahu Goldin" wrote:
The user clicks buttons on his user machine. The c# methods belong to your asp.net application that runs on your web server. You should make the
buttons to server controls and call methodTrue and methodFalse in the
serve-side onclick event handlers. To add client-side confirm functionality you need to add client-side onclick event handlers:

YesButton.Attri butes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmYes);
NoButton.Attrib utes["onclick"] = String.Format ("return
window.confirm( {0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussio ns.microsoft.co m> wrote in message
news:50******** *************** ***********@mic rosoft.com...
I would like to be able to call methodTrue() when the user clicks yes and methodFalse() when they click No. How do i accomplish that? here is
my code:

private void methodTrue()
{
//method false details
}
private void methodFalse()
{
//method false details
}
public void CreateMessagePr om2(System.Web. UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<scr ipt language='javas cript'>");
sb.Append("var results = window.confirm( '" + strMessage + "');");
sb.Append("if (results == true)");
sb.Append("{ alert('The value is true');}"); //call methodTrue
sb.Append("else ");
sb.Append("{ alert('the value is false');}"); //call methodFalse

sb.Append("</script>");

string strScript = sb.ToString();

if (!aspxPage.IsSt artupScriptRegi stered(strKeyPr ompt))
{
aspxPage.Regist erStartupScript (strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.To String();
}
}


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2519
by: Ralph Freshour | last post by:
I bought the PHP and MySQL For Dummies book and I'm having trouble understanding how I use PHP to verify and check forms input text data - the book shows snippets of code so I know how to do the actual check but I don't understand what web page the php checking code should go into? For example, I have a simple login web page (username and password) and then it calls my mainmenu php web page - I want to make a check that a username was...
4
4813
by: Derek | last post by:
Hi, I've built a rather large CGI that dumps a lot of data and a fairly complex javascript app out to the client's browser. Granted this may be poor style according to someone web design philosophy but that is the way things need to work for now here. The problem I'm having is that it appears that the browsers (IE, mozilla and netscape) are sometimes getting confused about wether the javascript code is running. By this I mean when I...
19
2025
by: What-a-Tool | last post by:
I have a school project (ASP) in which I have to call three different ASP pages from three different and identical (except for the form "action", obviously) HTM pages. This I have no problem with. However, as a personal learning project and challenge, I decided to see if I could code my initial HTM page to call any of the three ASP pages, depending on the condition of an option group. (3 buttons - id="function", id="sub", id="class") I...
5
1667
by: GIMME | last post by:
My question is ... How do I sort an Array on numeric, not character values ? In the example below, after sorting the contents are 1,10,2,3 . How do I get the contents to be 1,2,3,10 ? Thanks, em
8
5481
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
1
4035
by: jens Jensen | last post by:
Hello , i'm calling a webservice generated with oracle webservice java tools. I'm not able to add a web reference to a .net client the usual way with visual studio 2005. I was therefore provided with a set of Dll that implement the proxy needed to consume this web service. I'm now wrapping these dlls in a .Net webservice that can be consumed with Visual studio the familliar way.
0
5576
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
32
2793
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put some new ones on. In my code I am doing the following: For Each ctrl In tpMain.Controls If TypeOf (ctrl) Is CheckBox Then If ctrl.Name.StartsWith("chkS") Then ctrl.Visible = False
53
8416
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.