473,795 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to use confirm("myMess age") in ascx page

3 New Member
Ok, I'm somewhat new to .NET C# language and am having a bit of trouble.

I'm trying to run the javascript confirm() method from my ascx page but I'm currently using C# as the main language of the page so it's not recognizing the confirm method.

On previous attempts, I tried to do this straight from the radiobutton control that I want it linked to, but I have another method that I need to run after it if the user did click ok on the confirm dialog. When I tried to run the confirm method and a C# method i wrote in a <script language=C# > block, it runs the confirm method but never gets the the other method. This is the syntax i used: onclick="if(con firm('messageNe ededToDisplay') )otherMethod()" . I assume this is because of the difference in the languages used to run the methods.

So, is there a way to create a C# method that will do the same actions as the confirm() method (give a dialog box that will return true or false based on the user's decision)? I can list you all the references I am currently using if that will help decide whether I can do this with my current system setup and codebase.

Thanks for any and all help.
Dec 8 '06 #1
5 5432
scripto
143 New Member
By design, you cannot do message boxes on the server side - they must be called from the client side - vbscript or javascript. BUT, you can call the javascript from the server side. Take a look at how to use the RegisterClientS criptBlock() function.
Dec 8 '06 #2
strikefiend
3 New Member
Ok, I do not think I will be able to use RegisterClientS criptBlock() because the radiobuttons that I have the if(confirm()) block linked to are dynamically generated per qualified timeoff request per user that the system runs through for the current user if it's a manager.

So the problem, with most workarounds that I've found, is the fact that I don't know how many radiobuttons there is going to be on the page when it's rendered for the user, so I can't attach a method to it on server-side,

Here is the script block I'm trying to use on my ascx page, and, following that, the code snappet that generates the code for the radiobuttons on the page.

``````````````` ``````````````` ``````````````` ``````````````` ```````````

<script Language="C#" runat="server">
void Approve(object sender, EventArgs e)
{
RadioButton radbtn = (RadioButton) sender;
OnApproval(radb tn.ID);
}
</script>

``````````````` ``````````````` ``````````````` ``````````````` ```````````

js = "OnClick=\"if(c onfirm('Are you sure you want to Aprrove/Decline this ATO Request?')) this.Approve;\" ";

String radbtns = "&nbsp<inpu t type='radio' id='y" + requestId +"' name='"+ requestId + "' value='yes' "+js+" >yes</input>&nbsp;"+ "<input type='radio' id='n"+ requestId + "' name='"+ requestId + "' value='no' "+js+" >no</input>&nbsp";

``````````````` ``````````````` ``````````````` ``````````````` ```````````
The String Radbtns is passed, along with all the other data needed for all users the iteration goes through, to a label control that is created on the .ascx page and used in the ascx.cs page. And I can't register the script to this label as it would run and update all users info, which is not the desired effect.

I can provide the full pages if they will help.

Thanks for the help
Dec 8 '06 #3
kenobewan
4,871 Recognized Expert Specialist
You are able to call the client-side script that you need from the server-side. I program in VB.NET, but it will be similar:

Expand|Select|Wrap|Line Numbers
  1.  radiobutton.attributes.add("onclick","return confirm()") 
That way you can call it in the server-side you need. You won't find a client-side solution I believe. Hope that this helps.
Dec 11 '06 #4
strikefiend
3 New Member
Ok, I have almost totally redone my pages so that I can use the .Attributes.Add () function, but when I run my pages, it seems like the javascript isn't running on the clientside at all. No matter what I have the function do, nothing happens.

I've posted the new code at the bottom of the page so you guys can take a look at it. Tell me if you see anything that would cause my function not to work.


Thanks

ascx script block
Expand|Select|Wrap|Line Numbers
  1. void Do_Approve(object Source, EventArgs e)
  2. {
  3.     System.Web.UI.WebControls.RadioButton radbtn = 
  4.         (System.Web.UI.WebControls.RadioButton)Source;
  5.  
  6.     Approve(radbtn.ID);
  7. }
  8.  
ascx.cs radiobutton code block
Expand|Select|Wrap|Line Numbers
  1. System.Web.UI.WebControls.RadioButton radbtn = 
  2. new System.Web.UI.WebControls.RadioButton();
  3. radbtn.GroupName = requestId;
  4. radbtn.Text = optionText;
  5. radbtn.AutoPostBack = false;
  6. String tmp = "";
  7.  
  8. if(optionText == "yes")
  9. {
  10.     tmp = "y";
  11. }
  12. else
  13. {
  14.     tmp = "n";
  15. }
  16.  
  17. radbtn.ID = tmp+requestId;
  18. radbtn.Attributes.Add("Runat","Server");
  19. radbtn.Attributes.Add("OnClick","this.Do_Approve");
  20.  
  21. return radbtn;
  22.  
source code when view ascx page
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td>Your NAME Here</td>
  3.     <td>12/11/2006</td>
  4.     <td>12/18/2006</td>
  5.     <td>Noon</td>
  6.     <td>
  7.     <span Runat="Server">
  8.     <input id="_ctl3_y98" type="radio" 
  9.     name="_ctl3:98" value="y98" onclick="this.Do_Approve" />
  10.     <label for="_ctl3_y98">yes</label>
  11.     </span>
  12.     <span Runat="Server">
  13.     <input id="_ctl3_n98" type="radio" 
  14.     name="_ctl3:98" value="n98" onclick="this.Do_Approve" />
  15.     <label for="_ctl3_n98">no</label>
  16.     </span>
  17.     </td>
  18.     <td>No</td>
  19. </tr>
  20.  
Dec 12 '06 #5
kenobewan
4,871 Recognized Expert Specialist
OK - that you are not receiving an error message means that the JS is not being called. The first thing that I would do is remove the onClick in the button, so you don't have the client-side code being called before the server-side.

I would have the runat="server" in the form tag and use an asp:button rather than an html input one. That way the you can use the form event to trigger the button.add event.

I would then go through a debugging process - what we want to see is that your JS is being called and if you get an error it is a JS error. Once that happens, you have a JS and not a server-side code problem.

Tip - if this still isn't working then comment out as much C# code as possible until you just get the JS firing from the button.add event and build things up from there. Maybe an alert saying "Hello" to start.

Hope that this helps.
Dec 13 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1256
by: =?Utf-8?B?YmVuamk=?= | last post by:
Hi, Working with VB.NET 2005. I've got a mailmessage object and I set it up so that when the recipient replies, the reply address is a string of two different email addresses together. I used a line like the following: mymessage.Headers.Add(addressone + "," + addresstwo) Everything worked as expected when running on framework 2.0. However, after installing 2.0 SP1, the behavior broke. This header was stripped out of the
0
9672
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
9519
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,...
1
10164
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
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.