473,412 Members | 3,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

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 CreateMessageProm2(System.Web.UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
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.IsStartupScriptRegistered(strKeyPrompt) )
{
aspxPage.RegisterStartupScript(strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.ToString();
}
}
Nov 19 '05 #1
4 1488
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**@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.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 CreateMessageProm2(System.Web.UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
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.IsStartupScriptRegistered(strKeyPrompt) )
{
aspxPage.RegisterStartupScript(strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.ToString();
}
}

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.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmYes);
NoButton.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.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 CreateMessageProm2(System.Web.UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
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.IsStartupScriptRegistered(strKeyPrompt) )
{
aspxPage.RegisterStartupScript(strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.ToString();
}
}

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.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmYes);
NoButton.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.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 CreateMessageProm2(System.Web.UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
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.IsStartupScriptRegistered(strKeyPrompt) )
{
aspxPage.RegisterStartupScript(strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.ToString();
}
}


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

Eliyahu

"Mori" <Mo**@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.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.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmYes);
NoButton.Attributes["onclick"] = String.Format ("return
window.confirm({0})", msgConfirmNo);

You don't need to register any scripts.

Eliyahu

"Mori" <Mo**@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.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 CreateMessageProm2(System.Web.UI.Page aspxPage, string
strMessage, string strKeyPrompt)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='javascript'>");
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.IsStartupScriptRegistered(strKeyPrompt) )
{
aspxPage.RegisterStartupScript(strKeyPrompt, strScript);
}
}
catch(Exception exep)
{
string sMessage = exep.Message.ToString();
}
}


Nov 19 '05 #5

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

Similar topics

4
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...
4
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...
19
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....
5
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 ? ...
8
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 -------------------------------------------------------------------------------- ...
1
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...
0
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...
32
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...
53
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.