473,383 Members | 1,795 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,383 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 52192
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.