Calling Javascript function on server control click
-
Hi, I have written a function in javacript and I have created an ASP Button server Control.I want to call the function written in javascript as well as execute the method for buttonclick. There are two ways. A) 1. OnClick Event call the function 2. Onserverclick assign the Servermethod This is done in design time. B) 1.Call the javascript function in codebehind page - btnID.Attributes.Add("onclick","SetFocus();") 2.in design time call the Onserverclick the appropriate Servermethod. Which is the best way to handle.I need the answer in performance wise too. Thanks in Advance. Happy Coding MankayarKarasi
I have a similar problem. I want to run a CodeBehind function (OnClick) as well as run a javascript to open a pop up window. in the A) option in your post you have said that: 1. onclick Event call the function 2. Onserverclick assign the Servermethod How can I do this? please help. Thank you. _____________________________________________________ Yea! I could be wrong...
-
I have a similar problem. I want to run a CodeBehind function (OnClick) as well as run a javascript to open a pop up window. in the A) option in your post you have said that: 1. onclick Event call the function 2. Onserverclick assign the Servermethod How can I do this? please help. Thank you. _____________________________________________________ Yea! I could be wrong...
Method 1:
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) button1.Attributes.Add("onclick","window.open(""b.aspx"")") End Sub
Method 2:function openNew() { window.open("b.aspx"); } ... ... < asp :Button ID="Button1" Runat="server" Text="Button" OnClientClick="openNew();" />
Method3:Dim JS As String JS = "{" JS += "window.open(""somepage.aspx"")}" JS += "</" JS += "script>" Literal1.Text = JS </code> like this in different way u can open a popup window but i don't think that from server side code we can pop a window coz its a client side event, and we have to open it using client side scripting only. <CENTER><A href="HTTP://PRAKASH-K.BLOGSPOT.COM"> <DIV style="WIDTH:225PX;BACKGROUND-IMAGE: url(http://www.prakashshipping.org/image/prakash.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-COLOR: #ffffff"><BR><BR><br></DIV></A></CENTER> </x-turndown>
-
Method 1:
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) button1.Attributes.Add("onclick","window.open(""b.aspx"")") End Sub
Method 2:function openNew() { window.open("b.aspx"); } ... ... < asp :Button ID="Button1" Runat="server" Text="Button" OnClientClick="openNew();" />
Method3:Dim JS As String JS = "{" JS += "window.open(""somepage.aspx"")}" JS += "</" JS += "script>" Literal1.Text = JS </code> like this in different way u can open a popup window but i don't think that from server side code we can pop a window coz its a client side event, and we have to open it using client side scripting only. <CENTER><A href="HTTP://PRAKASH-K.BLOGSPOT.COM"> <DIV style="WIDTH:225PX;BACKGROUND-IMAGE: url(http://www.prakashshipping.org/image/prakash.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-COLOR: #ffffff"><BR><BR><br></DIV></A></CENTER> </x-turndown>
-
there is no method called
OnClientClick=".."
please help _____________________________________________________ Yea! I could be wrong...OOPS.. I did this example in Version 2.0 (Visula Web Developer 2005). Better you use HTML Input button instead of using asp:button
function Button1_onclick() { window.open("newwindow.aspx"); } < input id="Button1" type="button" value="button" language="javascript" onclick="return Button1_onclick();" /> </code> <CENTER><A href="HTTP://PRAKASH-K.BLOGSPOT.COM"> <DIV style="WIDTH:225PX;BACKGROUND-IMAGE: url(http://www.prakashshipping.org/image/prakash.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-COLOR: #ffffff"><BR><BR><br></DIV></A></CENTER> </x-turndown>
-
OOPS.. I did this example in Version 2.0 (Visula Web Developer 2005). Better you use HTML Input button instead of using asp:button
function Button1_onclick() { window.open("newwindow.aspx"); } < input id="Button1" type="button" value="button" language="javascript" onclick="return Button1_onclick();" /> </code> <CENTER><A href="HTTP://PRAKASH-K.BLOGSPOT.COM"> <DIV style="WIDTH:225PX;BACKGROUND-IMAGE: url(http://www.prakashshipping.org/image/prakash.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-COLOR: #ffffff"><BR><BR><br></DIV></A></CENTER> </x-turndown>
If I use a html link then I cannot put in server side code. I use a button like button1_OnClick(....) { ...some validation... //..and probable code to open a new aspx page in a new window } I cannot use a HTML link!:(( Help. _____________________________________________________ Yea! I could be wrong...
-
I have a similar problem. I want to run a CodeBehind function (OnClick) as well as run a javascript to open a pop up window. in the A) option in your post you have said that: 1. onclick Event call the function 2. Onserverclick assign the Servermethod How can I do this? please help. Thank you. _____________________________________________________ Yea! I could be wrong...
You might see the tip on adding a conformation popup to buttons: http://www.hintsandtips.com/ShowTip/107/hat.aspx[^] Rocky <>< www.HintsAndTips.com - Includes Developer Tips www.MyQuickPoll.com - 2004 Election poll is #33
-
You might see the tip on adding a conformation popup to buttons: http://www.hintsandtips.com/ShowTip/107/hat.aspx[^] Rocky <>< www.HintsAndTips.com - Includes Developer Tips www.MyQuickPoll.com - 2004 Election poll is #33
-
This only shows how to show a confirmation box... How can I use it to make a pop up window? _____________________________________________________ Yea! I could be wrong...
From the server side you can: Response.Write("window.open('mypopuppage.html');"); Response.End(); or on client side you can add in your Page_Load on the server: ImageButton1.Attributes["onclick"]="window.open('mypopup.html'); return true;"; This will open the popup window and then call your OnClick event on the server for the original page. Change the "return true" to "return false" if you do not wish the server side onClick to be called. Rocky <>< www.HintsAndTips.com - Includes Developer Tips www.MyQuickPoll.com - 2004 Election poll is #33
-
If I use a html link then I cannot put in server side code. I use a button like button1_OnClick(....) { ...some validation... //..and probable code to open a new aspx page in a new window } I cannot use a HTML link!:(( Help. _____________________________________________________ Yea! I could be wrong...
hey don't cry ... its really very simple .. u r making it complex void Button1_Click(object sender, ImageClickEventArgs e) { // do some validation whatever u want if (validate==true) { //open a new window //this'll open a child popup window for u String JS=""; JS = "{"; JS += "window.open('somepage.aspx')}"; JS += "</"; JS += "script>"; Literal1.Text = JS; } else { // do what ever u want //display some error message } Note: For smooth effects.. place the literal control at the bottom of the page so that the javascript will be fired when whole page is downloaded at client sied. <CENTER><A href="HTTP://PRAKASH-K.BLOGSPOT.COM"> <DIV style="WIDTH:225PX;BACKGROUND-IMAGE: url(http://www.prakashshipping.org/image/prakash.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-COLOR: #ffffff"><BR><BR><br></DIV></A></CENTER> </x-turndown>
-
From the server side you can: Response.Write("window.open('mypopuppage.html');"); Response.End(); or on client side you can add in your Page_Load on the server: ImageButton1.Attributes["onclick"]="window.open('mypopup.html'); return true;"; This will open the popup window and then call your OnClick event on the server for the original page. Change the "return true" to "return false" if you do not wish the server side onClick to be called. Rocky <>< www.HintsAndTips.com - Includes Developer Tips www.MyQuickPoll.com - 2004 Election poll is #33
I tried what you've told.
ImageButton1.Attributes["onclick"]="window.open('mypopup.html'); return true;";
But I have to open a page with aQueryString
. Please see theQueryString
problem in the above post. _____________________________________________________ Yea! I could be wrong... -
I have a similar problem. I want to run a CodeBehind function (OnClick) as well as run a javascript to open a pop up window. in the A) option in your post you have said that: 1. onclick Event call the function 2. Onserverclick assign the Servermethod How can I do this? please help. Thank you. _____________________________________________________ Yea! I could be wrong...
Firstly thanx for putting up with a novice like me... I have a form
Form1.aspx
on it are 3DropDown
s I have to build aQuerSting
depending on the values of theDropdown
s. I also have anImageButton
,OnClick
builds theQueryString
AND Opens a new pageForm2.aspx
. Like:ImageButton_Click(...)
{
string qs = "Form2.aspx?";
qs = qs + "s1=" + DorpDown1.SelectedValue.ToString();
qs = qs + "&s2=" + DorpDown2.SelectedValue.ToString();
qs = qs + "&s3=" + DorpDown3.SelectedValue.ToString();Response.Redirect(qs);//This opens Form2 in the same page...
// I want to open it in a popup....
}Sounds simple eh?... But plese help!! I tried your option by giving qs in
JS = "{";
JS += "window.open('qs')}";
JS += " JS += "script>";</pre>
It does not work!
I think the whole literal thing doesn't work.
YELP!PLEASE HELP ME GUYS
</x-turndown>