how to call a c# function if user click on ok button of java script confirm box in .net

hi, i have one problem that is i'm adding the new user to database, if that user is already exist in the database one pop up should display with message like 'user already exists are u sure you want to update the role of the user' with 'yes' and 'no ' buttons on pop up,

if user click on 'yes' button then it should call edituser() method of c3.net other wise it should reset the selected controls.

how to do this using extenal .js file with javascript confirm box

 

-1
neeraja
2/4/2008 5:33:47 AM
asp.net.client-side 24353 articles. 0 followers. Follow

7 Replies
2023 Views

Similar Articles

[PageSpeed] 59

Hi

When user click on "Yes" set a asp.net hidden field value to be "true" or "1", if user clicks on "No/Cancel" set the hidden field to be "false" or "0".

Based on the hidden field value call C# function in C#.

 


Shekar.Y(GGKTech)
http://ggktech.com
Dont forget to click “Mark as Answer” on the post that helped you.
-1
chandrashekar
2/4/2008 7:52:51 AM

can u please provide me one example how to do that one

-1
neeraja
2/4/2008 8:55:59 AM

This article show how to call C# function from javascript

http://forums.asp.net/t/999909.aspx

http://www.dotnet247.com/247reference/msgs/30/153188.aspx

 

 


Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
1
vik20000in
2/4/2008 9:01:39 AM
i'm not able to do can u please provide me how to declare hidden filed values and how to set those to confirm of javascript.

 i did like this:

void getSelectedUserDetails()

    {
        newConnection.Open();
        OracleCommand selectCommand4 = new OracleCommand("select roleid from userinrole where userid=&userid", newConnection);
        selectCommand4.Parameters.Add(new OracleParameter(":userid", OracleType.VarChar, 5));
        selectCommand4.Parameters[":userid"].Value = this.GridView1.SelectedValue.ToString();
        try
        {
            object obj11 = selectCommand4.ExecuteOracleScalar();
            int int1 = Convert.ToInt32(obj11.ToString());
            DropDownList1.SelectedValue = obj11.ToString();
            ListViewBind();
        }
        catch
        {
            DropDownList1.SelectedValue = "Select";
            ListBox1.Items.Clear();
            ClientScript.RegisterStartupScript(this.GetType(), "Select", "<script language='javascript'>confirm('No Role Is Assigned For User. Are You sure you want to Edit the user?');</script>");
            edituser ();
          }
if user clicks on yes or ok button of confirm box edituser() method needs to be called how to do this.
        newConnection.Close();
    }

 

1
neeraja
2/4/2008 10:09:21 AM

Something like this should work for you:

private void Button1_Click(object sender, System.EventArgs e)
{
 bool isConfirmNeeded = false;
 string confirmMessage = string.Empty;

 // All server side execution goes here and set isConfirmNeeded to true,
 // and create the confirmMessage text, if user confirmation is needed.

 if ( isConfirmNeeded )
 {
  System.Text.StringBuilder javaScript = new System.Text.StringBuilder();

  javaScript.Append("\n<script type=text/javascript>\n");
  javaScript.Append("<!--\n");

  javaScript.Append("var userConfirmation = window.confirm('" + confirmMessage + "');\n");
  javaScript.Append("__doPostBack('UserConfirmationPostBack', userConfirmation);\n");

  javaScript.Append("// -->\n");
  javaScript.Append("</script>\n");

  RegisterStartupScript(scriptKey, javaScript.ToString());
 }
}

private void Page_Load(object sender, System.EventArgs e)
{
 // Insure that the __doPostBack() JavaScript is added to the page...
 this.GetPostBackEventReference(this, string.Empty);

 if ( this.IsPostBack )
 {
  string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
  string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];

  if ( eventTarget = "UserConfirmationPostBack" )
  {
   if ( eventArgument == "true" )
    // User said to go ahead and do it...
   else
    // User said NOT to do it...
  }
 }
}

NC...

-1
NC01
2/4/2008 2:13:47 PM

 thanks a lot this code resolved my problem.

1
neeraja
2/5/2008 9:08:06 AM

Well then, something like this should work for you:

private void Button1_Click(object sender, System.EventArgs e)
{
 bool isConfirmationNeeded = false;

 // All server side processing goes here. Then set the boolean
 // isConfirmationNeeded to true, if user confirmation is needed.

 if ( isConfirmationNeeded )
 {
  System.Text.StringBuilder javaScript = new System.Text.StringBuilder();

  javaScript.Append("\n<script type=text/javascript>\n");
  javaScript.Append("<!--\n");

  javaScript.Append("var userConfirmation = window.confirm('No role is assigned for user. Are you sure you want to edit the user?');\n");
  javaScript.Append("__doPostBack('UserConfirmationPostBack', userConfirmation);\n");

  javaScript.Append("// -->\n");
  javaScript.Append("</script>\n");

  RegisterStartupScript(scriptKey, javaScript.ToString());
 }
}

private void Page_Load(object sender, System.EventArgs e)
{
 // Insure that the __doPostBack() JavaScript is added to the page...
 this.GetPostBackEventReference(this, string.Empty);

 if ( this.IsPostBack )
 {
  string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
  string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];

  if ( eventTarget = "UserConfirmationPostBack" )
  {
   if ( eventArgument == "true" )
   {
    // User said to go ahead and do it...
    this.updateUser();
   }
   else
   {
    // User said NOT to do it...
   }
  }
 }
}

private void updateUser()
{
 // Database code to update the user goes here...
}

Note that RegisterStartupScript and RegisterClientScriptBlock have changed since version 1.1 and you will get a compiler warning with the above.
See http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx for more info.

NC...

-1
NC01
2/5/2008 5:30:22 PM
Reply:

Similar Artilces:

Can I call a client side\java script function by clicking a menu item from the menu control?
I would like to use the menu control to populate a listview without the menu causing a postback.  Is there  way to call a javascript function by selecting a menu item.  Thanks for any help. HI, You can try to use ClientScriptManager..::.RegisterClientScriptBlock Method to call the client script of the page in the menu's MenuItemClick event. But you shold make sure the menuitems have no navigateUrl, or else the page will redirect to the navigateUrl without postback, so the MenuItemClick  event will not be fired. About the RegisterClientScriptBlock , you refer this msdn article: http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx   hope it helps.  Amanda WangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Call server-side page function from client-side button click
I have an existing ASP application that I am migrating to ASP.net. In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data. I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx, the code is listed below. Someone suggested to use System.Net HTTP classes su...

communication between client side(java script) and server side in .net project
I have a question which is, when building a .net project, we are able to use server side code and client side code(java script). How do they communicate? Thanks Client Side coding works with the WebBrowser. So when ever you write client side code you have to keep browser compatability in your mind and you have to code. Server Side code works with Web Server (IIS) and it's ASPNET ISAPI's. The won't directly communicate with each other. But using AJAX you can all server side code from Client Side! Example article on Ajax@ http://www.devarticles.com/index2.php?option=content&task=view&id=1050&pop=1&hide_ads=1&page=0&hide_js=1Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti Thanks, May I say, when an user clicks a button, pop up box show up. are they communicate? When User Clicks on Button, a popup comming means, on that Button onclick event you might have some Client Side JavaScript. That's why you got popup. So are they communicate? As Browser will act for onclick event, message box shows up. Is click and Sever on sommunicating for this. No it's puerly client side event. But some times, when you click button it submitts to server and does some process as you needed and get's the results back, in that instance you can think browser send request to server and server process it and responds back to browser. hope I made it clear to you!  Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoga...

want to call one c#.net function in one user control from another user control
hi i have two user controls info.ascx and personal.ascx i have a function like in info.ascx i have a function like showdetails() {   } now i want to access this function from personal.ascx can i do this ? thanks in advance. shwetaThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path  you should better create a class where you will define the "functions" that you need in both files. declare "static" the function and call it like nameofclass.nameoffunction In a web project you can...

how to call java script function in vb.net ?
I have working with grid view and get records from database if the records exceding 1000 then I need to display confirm dialog box through javascript ? if click ok then it will display the records in gridview and if click cancel then it will create a message into label .   want to know where to call java script function on the button that will display this javascript dialog.Basim Hi, try this... //Code to get the datasource dataset ds if(ds.Tables[0].Rows.count > 0) {     Page.ClientScript.RegisterStratUpScript(this.GetType(),"showal","ShowGri...

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

java script function in .net function
Dear All,I’m trying to open up a window with a form in it, but first I need to make sure that the user checked at least one or more item on a list with checkboxes in each row on the page where I push the button to open the window from.I use the following simple code:Public Sub btnLog_onClick(ByVal sender As System.Object, ByVal e As System.EventArgs)           Dim myCsv = getTickedItems(1)         If myCsv = "" Then             Exit Sub  ...

how to call java script function in button click event
i have a java script function defined in the .aspx page.i have a button.now i need to call that function in the button click event in aspx.cs page.how can i do it?  in the code-behind file:  Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) Me.ClientButton.Attributes.Add("onclick", "On_ClientClick();") End Sub   in-line: <asp:Button ID="ClientButton" runat="server" Text="Click" OnClientClick="On_ClientClick();" />   I don't do...

XUL to click OK on java script confirmation box
I am trying to create an extension that observes when a popup is created. It needs to automatically click the OK button on a java script confirmation dialog for the end user. I have some code but it doesn't work. Can anyone offer any advice here? My current code is at http://pastebin.ca/1174800 Thanks. On Sun, Aug 17, 2008 at 12:40 AM, MikeNereson <mikenereson@gmail.com> wrote: > I am trying to create an extension that observes when a popup is > created. It needs to automatically click the OK button on a java > script confirmation dialog for the end user. I hav...

call client side java script on Gridviewbuttonfield click
 Hi all, I have a gridview in which i used button field to delete record from database on "onrowcommand" event of gridview. It works properly. But I want confirmation of delete before deleting record from database on client click. so i think for that i need to call javascript confirm box on click and if it returns true then only onrowcommand event of control to be executed. Is it possible that way.if yes then suggest the code otherwise suggest another way.  <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenera...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Button click function client and server side call backs
Hi Every one          I am trying to call a javascript funtion to validate the input of two text boxes and if the function returns true I want the code to go to the button click event to store values of the text boxes in the tables. But for some reason I am not able to do that. Please hlep me here.   Here is the code that I am using to call the javascript function, but its giving me error <HEAD>  <title>CallBackButton</title>      <script language="JavaScript">  function...

calling given javascript script from vb.net button click
Respected membersCan anybody please help me to call the script given below after vb.net button click    The script below displays google map on normal html page.when i tried using ClientScript.RegisterStartupScript , iam getting error on line 7 missing ; errorIf you can provide the modified code i'll be grateful to u.Thanks in advance<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xQpTR6YCxnSXrgb0dAWLhf5sIEOjRResgehB9eed2b9p_qltU3hRBfG4g"      type="text/javascript">&l...

How to call C#.net function in one usercontrol from another user control
hi everybody i have one function like bindcs() {   } in my one user control. now i want  to call this function from my another user control. i tried to do this by findcontrol but it get the whole control i dont get it its function. can anyone help me? thanks shwetaThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path You will need to declare the method as public and then cast the control that you get from FindControl to be the type of the user control. A good approach for this is to implement an event on t...

How to call java script function in vb.net(aspx.vb file)
Hi, i have written following script in aspx file which works fine:  ----------------------------------------------------------------------------------<script type="text/javascript" language="javascript"> function Enable_ddlyear() {  document.form1.TxtStartDate.disabled=true ; document.form1.TxtEndDate.disabled=true ;var x=document.getElementById("ddlyear") x.disabled=false }  function Enable_dates() {document.form1.TxtStartDate.disabled=false ; document.form1.TxtEndDate.disabled=false ;document.form1.ddlyear.disabled=true ; ...

Need help converting a C#/.NET method into client-side (javascript) function
Hey Guys, I have implemented an AJAX Toolkit CalendarExtender.  I have a method 'CheckDate' in javascript (followed a tut!) that checks to see if the user selected a date > DateTime.Now(). Well, I have a few other things to check but not sure how to do them in javascript, so I'm hoping someone here can help me.  I mean, i can somewhat convert it but it'll be too mangled, I'd rather learn the right way.  I'm attaching the code and any help will be appreciated.  1 protected string CheckDateErrors(string dateGiven) 2 ...

How to display a client-side confirm dialog box if the user clicks on the first row in my datagrid
I could n implement that, this what I tried: I define my datagrid with :  <ItemTemplate> <a id="MenuItem".......><%#container............>  pls check my aspx html code bellow. Thn, In the ItemDataBound event handler of my datagrid, I test if e.Item.ItemIndex=0, if so, I create an object of type control and assign it to e.item.controls(0) , then I try to add the client side property: atributes(....) to that control. The pb is: the control object that I create doesn t take the client property :  attributes(“onclick”)=…. My question is:  What type are...

calling server side function from client side script
i have a web form that includes a function named "koko()" in its server side class i want to write a script code in in its HTML script that will be run at the client side, and this client side script will call the function "koko()" from the server side. in brief : i want to call a server side function from a client side script... can you help me in this You can't call server-side code directly from client-side code. You can, however, trigger a postback that your server-side code watches for and triggers the server-side code appropriately. You can do some ...

Client side script calling Server side functions
Hi, I'm currently developing an ajax.net enabled aspx page that contains a usercontrol (which is based on the listbox but extends it to include icons to represent invalid data). http://www.djcharlie.co.uk/WeeeCareResolutionCentre.jpg I want the onClick event of the selected TR to call an asp.net server function which then populates the controls to the right hand side in the page. Obviously because the row is just rendered HTML overriden from the base class I can only assign a javascript function to the onClick event. So I need a way of calling a server side function that will populate that will populate the right hand controls from an object based on the row's ID. I tried playing around with EnablePageMethods after some google-hunting but a) I don't have have that attribute on my scriptmanager (and I have reinstalled the extensions again) and b) apparently it can only call static methods and of course static methods cannot populate controls at page level.  Thanks in advance, DJCharlie Just to put this in English, you need to get the address data from the database pertaining to the Company that is selected on the left, and update the values in the textboxes on the left with it, without effecting a full postback?  Is that right?If so, have a look at the xmlhttprequest object in javascript.  This is one of the most straightforward explanations of how to use it, and while the example is classic ASP, you should get the jist. Regards Mike [MVP - ASP/A...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of developing. The trick is to use the "Src" attribute of the @Page directive. Check out the link if you are inclined. You are welcome to download the code if you are interested further, found at the same link. (Note that the reason that I looked for a way to do this is because I wanted to have the option to include some VB.NET-based demos at my site. Since my site is a C#.NET ASP.NET, I was told that there was no want to do this. Therefore, I looked for a workaround and just happened to find one.) Enjoy (and then get back to work!) http://www.NetBrainer.com you are right !!!mixing languages could cause unknow and uncontrolled problems !!! if a developer has to mix ....the practical way is to create a new project with different language and what will be absolutely fine !!!thanks mkamoski for raising this issue !!Fadil Alnassar www.fadilalnassar.com | FREE Nodil Tab Controlhttp://www.mefranchisi...

Calling server side sub from client side button click
Hi, I have some javascript in my asp.net page, and a function within that, which is run when the client side form is submitted. What I need is for that function to run, which updates a server side variable, then following that a server side sub should run, using that (newly updated) variable. I have currently set it up with the  onsubmit= tag of the client side form running the first (JavaScript) function, and then the submit button at the bottom of the client side form calling the server side sub with its onClick property. The (probably quite daft!) thinking behind that was that the on...

Can you call a c# on the server side from javascript functions on client side
Hello guys This is something intresting I have come across during development. I have a javascript written in a .JS file , to my knowledge the .js files are executed on the server side. But security concerns with java script that these .js files can be access by connecting to port 80 of the server . So an ultimate alternative reminas to call c# code from a java script function. Can anyone Help me on this matter Regards Nihar Hi Nihar, Usually .js files executed on client side. Please explain your configuration.Leon LangleybenMCSD, ASP.NET MVPBlog...

How do I call server side function in client side script without using __doPostBack
Hello, My page has a server side panel that is hidden when the page loaded, checkboxes inside of the datagrid, and buttons.  If at least one checkbox is not clicked and the user click on the button, I show the panel.  When the user click on one of the checkbox, I want to hide the panel.  Onclick on the checkbox I already have a cleint function to change the row color.  I don't want to use __doPostBack.  Don't want to do postback. My question are: How do I either have checkbox onclick called both client and server side functions.  Or have the client side function call the server side function to hide the panel. Thank you Hi Kathy - If you have a Panel with the ID of pnlError, and a CheckBox with the id of chkRow, you could use the following logic (in the Page Load event) I'm assuming VB, let me know if you need C#     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        chkRow.Attributes.Add("onClick", "document.getElementById('" & pnlError.ClientID & "').style.display='none';")     End Sub To show the panel, use style.display=''; Tyler, Thank you for the tip.  It works, but.. I already have the onClick atttributes added for client side for something else.  Can I have the OnClick doing more than one? ' add on click to each checkbox' chkSelect.Attributes.Add("OnClick", "javascript:c...

Call server-side script from client-side script
Hi to all, I would like to ask you How can i call from client-side script a server-side script and to have the result from the server-side script in the client-side script. For example, i wand to call a function writing in server-side (DynaScript) script from a client-side script (JAVASCRIPT) and to have an answer from the function. Thanks in advance. Nick, One way that you could get round this is to write your client script code as you would server script eg. <SCRIPT language=javascript> function getValue()... would be written as: <% psDocument.WriteLn("<SCRIPT language=javascript>"); psDocument.WriteLn("function getValue()"); %> This way your client value is essentially your server side value(and vice versa) and can be accessed easily. Davlon nick wrote: > Hi to all, > I would like to ask you How can i call from client-side script a > server-side script and to have the result from the server-side script > in the client-side script. For example, i wand to call a function > writing in server-side (DynaScript) script from a client-side script > (JAVASCRIPT) and to have an answer from the function. > Thanks in advance. From client script you need to link to a page in order to fire off a server script. You can link to the current page and pass parameters to indicate it's a reload or whatever and process based on that. A server-side script can create HTML ...

Web resources about - how to call a c# function if user click on ok button of java script confirm box in .net - asp.net.client-side

Talk:Trigonometric functions - Wikipedia, the free encyclopedia
This article is within the scope of WikiProject Mathematics , a collaborative effort to improve the coverage of Mathematics on Wikipedia. If ...

Resource sector may outsource finance functions to Asia
Outsourcing financial functions to Asia is one tactic struggling Australian energy and resources companies may use this year to survive the slump ...

Using Functions to Make Better Abstractions
... (code that is tightly coupled to its own implementation details). I was wrong. I was wrong because I had an incomplete understanding of functions. ...

Media devices sold to feds have hidden backdoor with sniffing functions
... AMX NX-1200 , a programmable device used to control AV and building systems. The researchers first became suspicious after encountering a function ...

A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003
**[A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003](http://www.j-bradford-delong.net/movable_type/2 ...

Here's how squads and iron sights will function in Rising Storm 2: Vietnam
... roles and create a squad, and the creator can name, lock, or invite others to their little group. The more an outfit fills up, the more functions ...

Yahoo Begins Grim Job of Closing Functions, Laying Off Staff
Yahoo Food is closing, and other digital magazines on tech, travel and beauty are also scheduled for closing or major cutbacks.

Don’t tase me, bro: Study shows being shocked by a Taser disrupts brain function
Researchers at Drexel shot a bunch of college students with 50,000 volts. The result? Short-term declines in cognitive function comparable with ...

Opioids Do Not Improve Physical Function In Patients With Neuropathic Pain
While opioids may alleviate pain in some chronic pain patients, their effectiveness when it comes to restoring physical function in patients ...

A 3D Printed Jet Engine Appears to Function
... jet engine . You may remember seeing a 3D printed jet engine grace our front page back in October. That one was beautiful didn’t function . ...

Resources last updated: 2/21/2016 7:19:44 PM