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 -
//...
-
protected void Button1_Click(object sender, EventArgs e)
-
{
-
ClientScript.RegisterStartupScript(
-
typeof(string),
-
"hello", "alert('hello');" +
-
Page.ClientScript.GetPostBackEventReference(this, ""),
-
true);
-
}
-
-
//...
-
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
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.
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
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
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. - ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');" + Page.ClientScript.GetPostBackEventReference(this, "") + ";", true);
Please try this one, instead. - ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');" + Page.ClientScript.GetPostBackEventReference(this, "") + ";", true);
Thanks alot, works great :D
-Biff
Thanks alot, works great :D
-Biff
I'm glad it helped you.
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!!!
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.)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
===========
|
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
|
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...
|
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...
| |
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:...
|
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
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |