473,786 Members | 2,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble calling alert() from codebehind with masterpage and update panel

39 New Member
Hello,

I am using VS2005 to code webapps using C#.
I am trying to call the javascript function alert() from my codebehind. I am using master pages and AJAX.

My page structure is as follows:

MasterPage.aspx
ScriptManager1
UpdatePanel1
ContentPlaceHol der1

Default.aspx (with MasterPage.aspx as its masterpage)
Button1 - OnClick="Button 1_Click"

Default.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. //...
  2.     protected void Button1_Click(object sender, EventArgs e)
  3.     {
  4.         ClientScript.RegisterStartupScript(
  5.             typeof(string),
  6.             "hello", "alert('hello');" +
  7.             Page.ClientScript.GetPostBackEventReference(this, ""),
  8.             true);
  9.     }
  10.  
  11. //...
  12.  
Well that's how I thought it should look.
But it doesn't work in IE7 unfortunately.

I know that I can get an alert with OnClientClick=" alert('hello'); " but in my real application I have much heavier logic in my Button1_Click event that cannot be performed in javascript easily.

Any ideas on how I would call alert from the code behind?

Thanks,
-Biff
Aug 30 '07 #1
8 11777
acoder
16,027 Recognized Expert Moderator MVP
Biff, welcome to TSDN!

You posted this in the Javascript forum, but since your problem relates to .NET, I'll pass you over to the experts in that forum who would be much better equipped to help you with your problem.
Aug 31 '07 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi,
Im not proficient with javascript,
but what you wud want to do is to load the javascript (whatever you wrote, in the respective javascript function for button click) and register it on page load.

Cheers
Aug 31 '07 #3
BiffMaGriff
39 New Member
Hi,
Im not proficient with javascript,
but what you wud want to do is to load the javascript (whatever you wrote, in the respective javascript function for button click) and register it on page load.

Cheers
Hey Shashi,

Thanks for responding. I tried doing that and it works fine without the updatepanel. But when my button is inside the update panel I do not get the alert. :(

-Biff
Aug 31 '07 #4
dotneto
36 New Member
Hey Shashi,

Thanks for responding. I tried doing that and it works fine without the updatepanel. But when my button is inside the update panel I do not get the alert. :(

-Biff
Please try this one, instead.

Expand|Select|Wrap|Line Numbers
  1. ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');" + Page.ClientScript.GetPostBackEventReference(this, "") + ";", true); 
Aug 31 '07 #5
BiffMaGriff
39 New Member
Please try this one, instead.

Expand|Select|Wrap|Line Numbers
  1. ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');" + Page.ClientScript.GetPostBackEventReference(this, "") + ";", true); 
Thanks alot, works great :D

-Biff
Aug 31 '07 #6
dotneto
36 New Member
Thanks alot, works great :D

-Biff

I'm glad it helped you.
Aug 31 '07 #7
sara4
9 New Member
Finally something that works!!!!! I read so many topics on alert from code behind and this is the only one that works for me! Thank you!!!
Sep 16 '08 #8
sara4
9 New Member
Any ideas on how to do the same with Confirm? I need to catch the value user selected (for example: 'Are you sure you want to delete the record?' if yes, i go forward and delete the record.)
Sep 16 '08 #9

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

Similar topics

1
2176
by: Steven K | last post by:
Hello, In my codebehind file, I am trying to call a sub procedure that is in my MasterPage, but I am getting an error: Error 1: BC30451: Name 'LoadMenu' is not declared. c:\inetpub\wwwroot\price_insx\MenuCode.aspx.vb 19 ---- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
5
4046
by: sck10 | last post by:
Hello, I am converting a class in the App_Code folder from c# to vb and am having problems calling the sub procedure. I have created a Sub called HidePanels in the class "General". When I try to declare a new object of this type in my codebehind, I get the error: "Type 'HidePanels' is not defined". Any help with this would be appreciated. Thanks, sck10 code behind ===========
7
33872
by: =?Utf-8?B?Qw==?= | last post by:
I have a dropdown list as below. I add an onchnage attribute in my codebehind to call some Javascript. I want to get the selected text from my dropdown. What am I doing wrong below? <asp:DropDownList ID="ddlStatus" runat="server" /> In my codebehind
3
3808
by: Jeremy | last post by:
I've got a button in an update panel. In the click event of the button (server side code), I perform some logic and under certain criteria I want to display an alert to the user. I've tried several things like adding an onload javascript event to one of the controls in the update panel, and I've tried adding a lteral control to the update panels ContentTemplateContainer.Controls collection where the literal controls contents where...
4
13034
by: faraz | last post by:
I have a javascript function that i want to call masterpage load method called. I cant add onLoad event of body or table in master page. I have put the call to script function in <form>, it works on every pageLoad. seems my problem is solved. But when the pages uses UpdatePanel and it gets asynchronously postback. the function call at master page doesnt execute????? thought master page Load event gets called even when pages are in...
4
6054
by: pablorp80 | last post by:
Hello, Here is what I need: I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback. Here is the problem: I am using AJAX and MasterPages as well as an update panel, the textbox is in a panel. I have tried to do it using different java scripts but I can't get it to work because I am not using asp forms, instead I am using Containers. Here is my code:...
2
1662
by: CrystalMikeMD | last post by:
Greetings, I've been at this problem for some time now and have decided to seek out some help. Essentially, this is what I have. A basic ASP.NET 2.0 page. On this page is the standard <formtag. Under that, we have an UpdatePanel object where the rest of my partial rendering controls live. There is simply a basic control, such as a Literal or Label in the UpdatePanel. When a button is clicked on the page, I want to send out
4
3589
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in the...
1
4590
by: splendid9 | last post by:
Update panel and masterpage problem i hav a problem with updatepanel on the page. i have 2 update panels on the page which are wortking fine, but there is a display which is on masterpage used by the page which is not displaying as it is partial postback...and i cannot place it in other update panel as it is getting error display from masterpage which i cannot change as it is usde by lot of other pages, anyone hav ny idea how can i get the...
0
9497
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
10363
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
10110
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
8992
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...
1
7515
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
6748
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.