473,408 Members | 1,955 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,408 software developers and data experts.

How do I fire a server side button click event from javascript?

Hi,

I need to fire a server side button click event from my client side
javascript. The client side javascript code follows:

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");
form1.<%= hiddenTextField.ClientID %>.value = strname;
form1.<% =btnSubmit.ClientID %>.click();

}
</script>

You can see that I'm trying to use the "click();" event for the <asp:
"btnSubmit" button but it dosen't seem to work.
Any ideas?!

Thanks in advance for your help.

Steve

May 27 '06 #1
3 52198
the ModalPopup under ATlas Toolkit will do that for you ...

http://atlas.asp.net/atlastoolkit/Mo...odalPopup.aspx
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Steve Kershaw" <st***********@yahoo.com> escreveu na mensagem
news:11*********************@g10g2000cwb.googlegro ups.com...
Hi,

I need to fire a server side button click event from my client side
javascript. The client side javascript code follows:

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");
form1.<%= hiddenTextField.ClientID %>.value = strname;
form1.<% =btnSubmit.ClientID %>.click();

}
</script>

You can see that I'm trying to use the "click();" event for the <asp:
"btnSubmit" button but it dosen't seem to work.
Any ideas?!

Thanks in advance for your help.

Steve

May 27 '06 #2
I'm sorry, maybe I didn't explain myself properly. I don't need a popup
that allows the user to enter some text (their name in this case). The
javascript I displayed already does that:

strname = prompt("What is your name", "");

What I need is, after the user enters their name and clicks the OK
button on the javascript (client side) prompt popup, I need the
javascript function to call a ( server side, ASP.NET, C# ) OnClick
event.... Like this:

form1.<% =btnSubmit.ClientID %>.click();

The server side event looks like:

protected void btnSubmit_Click(object sender, EventArgs e)
{
TextBox2.Text = hiddenTextField.Value;
Response.Write("Your name is: " + hiddenTextField.Value);
}

However, it dosen't work!
Can anyone help?!!

Steve

May 27 '06 #3
Hai Steve,

I hope u r button id is "btnSubmit"

Step 1:
In the server side page load event just add this code...

Page.GetPostBackEventReference(ImageButton1)

Step 2:-

Try calling this line " __doPostBack('btnSubmit','OnClick');"

call the above function "callPostBack" after u r prompt
statement.

eg:-

<script language="javascript" type="text/javascript">
function myFunction()
{
var strname;
strname = prompt("What is your name", "");

// if its a valid name then just call post back..
__doPostBack('btnSubmit','OnClick');

}
</script>

The java script will trigger a postback as if it was initiated by
the Button.. u can handle it on u r server side

hope this helps u

Regards
Vinu

May 27 '06 #4

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

Similar topics

3
by: ~J~ | last post by:
Hi everyone I'm positive this is possible, just never needed it until now and I don't have a clue where to start I have an XML document that is attached to an XSL style sheet, within this XSL...
4
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
1
by: Andy Rose | last post by:
..Hi all, I want to catch an 'enter' keypress event on a web form and submit the form as if a button had been clicked rather than the default post back behaviour. I know the following javascript...
6
by: shil | last post by:
I have a server side button that needs to do some preperation and afterwards, if everything goes well, open a new browser with a specific url. I know how to execute javascript from a server side...
4
by: Winista | last post by:
I have a page with bunch of user controls and standard controls on the page. And then I have a Button control on the page which is used to save the data on server side. All was working fine and...
17
by: Eric | last post by:
I'm new to JavaScript and I wrote this code to play with. Oddly, if I enter text in a box and then press the button, I only get the onChange event for the text box and not the button's onclick...
1
by: babashankar | last post by:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var change = false; function showmsg(id) { var res =...
19
Frinavale
by: Frinavale | last post by:
I'm in the middle of implementing a custom Ajax enabled Server Control. At this point I need help finding the answer to an Ajax Framework question...here it goes: I have a Server Control that...
4
yarbrough40
by: yarbrough40 | last post by:
can any one tell me if there is a way to pass a string variable to a button click event? ultimately I am looking to fire client side Javascript "__doPostBack('Button1','click','')" and have the...
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
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
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...
0
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,...
0
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...
0
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...

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.