473,568 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating Javascript from a button in Code-behind

I have a web form, with c# code-behind.
I have a listbox on the form, bound to a dataset.
I want to have 2 buttons/hyperlinks/etc. beside the listbox.
When they are clicked, I want to launch a popup form, passing it some
information from the listbox (record id) and the linked information.

If I could show the data in place of the page showing, I know how to get the
data and use Response.Redire ct().
Since it needs to be a popup, I know how I could use a javascript, such as:
window.open("my nextpage.aspx", "_blank", "height=300 , width=450,
left=100, top=100, " + "location=n o, menubar=no, resizable=no, " +
"scrollbars =no, titlebar=no, toolbar=no", true);

I know that in my PageLoad() method, I could add an Onclick() method to a
hyperlink, using the .

But I don't want to do a roundtrip every time the user clicks an entry in
the listbox.

So is there some way a hyperlink button could, in the code-behind put a
javascript command into the html re-emited to the user?

Thanks!
Nov 18 '05 #1
4 1974
Add an Attribute in the code-behind.
txtFirstName.At tributes.Add("o nclick","fnJava ScriptCall()");

You could also write the client script in the code-behind like this:
public void writeScript()
{
string script = "<script language=\"java script\">";
script += "function fnJavaScriptCal l(){";
script += " Code...";
script += " }";
script += "</script>";
this.Page.Regis terStartupScrip t(script);
}

Regards,
-Brian K. Williams

"Nevyn Twyll" <as****@hotmail .com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
I have a web form, with c# code-behind.
I have a listbox on the form, bound to a dataset.
I want to have 2 buttons/hyperlinks/etc. beside the listbox.
When they are clicked, I want to launch a popup form, passing it some
information from the listbox (record id) and the linked information.

If I could show the data in place of the page showing, I know how to get the data and use Response.Redire ct().
Since it needs to be a popup, I know how I could use a javascript, such as: window.open("my nextpage.aspx", "_blank", "height=300 , width=450,
left=100, top=100, " + "location=n o, menubar=no, resizable=no, " +
"scrollbars =no, titlebar=no, toolbar=no", true);

I know that in my PageLoad() method, I could add an Onclick() method to a
hyperlink, using the .

But I don't want to do a roundtrip every time the user clicks an entry in
the listbox.

So is there some way a hyperlink button could, in the code-behind put a
javascript command into the html re-emited to the user?

Thanks!

Nov 18 '05 #2
Okay, but how would I get the ID Value of the currently selected row in the
listbox in order to use it in the redirect of the javascript function?
That's what I don't quite get how to do.
"Brian K. Williams" <wi*******@mill enia.com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.phx.gbl...
Add an Attribute in the code-behind.
txtFirstName.At tributes.Add("o nclick","fnJava ScriptCall()");

You could also write the client script in the code-behind like this:
public void writeScript()
{
string script = "<script language=\"java script\">";
script += "function fnJavaScriptCal l(){";
script += " Code...";
script += " }";
script += "</script>";
this.Page.Regis terStartupScrip t(script);
}

Regards,
-Brian K. Williams

"Nevyn Twyll" <as****@hotmail .com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
I have a web form, with c# code-behind.
I have a listbox on the form, bound to a dataset.
I want to have 2 buttons/hyperlinks/etc. beside the listbox.
When they are clicked, I want to launch a popup form, passing it some
information from the listbox (record id) and the linked information.

If I could show the data in place of the page showing, I know how to get

the
data and use Response.Redire ct().
Since it needs to be a popup, I know how I could use a javascript, such

as:
window.open("my nextpage.aspx", "_blank", "height=300 , width=450,
left=100, top=100, " + "location=n o, menubar=no, resizable=no, " +
"scrollbars =no, titlebar=no, toolbar=no", true);

I know that in my PageLoad() method, I could add an Onclick() method to a hyperlink, using the .

But I don't want to do a roundtrip every time the user clicks an entry in the listbox.

So is there some way a hyperlink button could, in the code-behind put a
javascript command into the html re-emited to the user?

Thanks!


Nov 18 '05 #3
This should do the job..

DropDownList1.A ttributes.Add(" onchange","fnGe tSelectedValue( this)");

function fnGetSelectedVa lue(oElement)
{
var strSelectedValu e = oElement.option s[oElement.select edIndex].value;
alert(strSelect edValue);
}

Or

DropDownList1.A ttributes.Add(" onchange","fnGe tSelectedText(t his)");

function fnGetSelectedTe xt(oElement)
{
var strSelectedValu e = oElement.option s[oElement.select edIndex].text;
alert(strSelect edValue);
}
-Brian

"Nevyn Twyll" <as****@hotmail .com> wrote in message
news:uS******** *****@tk2msftng p13.phx.gbl...
Okay, but how would I get the ID Value of the currently selected row in the listbox in order to use it in the redirect of the javascript function?
That's what I don't quite get how to do.
"Brian K. Williams" <wi*******@mill enia.com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.phx.gbl...
Add an Attribute in the code-behind.
txtFirstName.At tributes.Add("o nclick","fnJava ScriptCall()");

You could also write the client script in the code-behind like this:
public void writeScript()
{
string script = "<script language=\"java script\">";
script += "function fnJavaScriptCal l(){";
script += " Code...";
script += " }";
script += "</script>";
this.Page.Regis terStartupScrip t(script);
}

Regards,
-Brian K. Williams

"Nevyn Twyll" <as****@hotmail .com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
I have a web form, with c# code-behind.
I have a listbox on the form, bound to a dataset.
I want to have 2 buttons/hyperlinks/etc. beside the listbox.
When they are clicked, I want to launch a popup form, passing it some
information from the listbox (record id) and the linked information.

If I could show the data in place of the page showing, I know how to get
the
data and use Response.Redire ct().
Since it needs to be a popup, I know how I could use a javascript,
such
as:
window.open("my nextpage.aspx", "_blank", "height=300 , width=450,
left=100, top=100, " + "location=n o, menubar=no, resizable=no, " +
"scrollbars =no, titlebar=no, toolbar=no", true);

I know that in my PageLoad() method, I could add an Onclick() method
to a hyperlink, using the .

But I don't want to do a roundtrip every time the user clicks an entry in the listbox.

So is there some way a hyperlink button could, in the code-behind put

a javascript command into the html re-emited to the user?

Thanks!



Nov 18 '05 #4
That looks great.
However, how do I generate the code I want dynamically, in the code-behind?

Basically, I want the user to have free-reign with the listbox on the client
side, and when they press a button (hyperlink button, etc.), I want to pop
up a window with a bunch of information from the line they selected in the
listbox, which is easy to get to from the code-behind?

Should I just write a javascript method to do it anyway, and if so, how do I
access an asp control from javascript?

"Brian K. Williams" <wi*******@mill enia.com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.phx.gbl...
Add an Attribute in the code-behind.
txtFirstName.At tributes.Add("o nclick","fnJava ScriptCall()");

You could also write the client script in the code-behind like this:
public void writeScript()
{
string script = "<script language=\"java script\">";
script += "function fnJavaScriptCal l(){";
script += " Code...";
script += " }";
script += "</script>";
this.Page.Regis terStartupScrip t(script);
}

Regards,
-Brian K. Williams

"Nevyn Twyll" <as****@hotmail .com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
I have a web form, with c# code-behind.
I have a listbox on the form, bound to a dataset.
I want to have 2 buttons/hyperlinks/etc. beside the listbox.
When they are clicked, I want to launch a popup form, passing it some
information from the listbox (record id) and the linked information.

If I could show the data in place of the page showing, I know how to get

the
data and use Response.Redire ct().
Since it needs to be a popup, I know how I could use a javascript, such

as:
window.open("my nextpage.aspx", "_blank", "height=300 , width=450,
left=100, top=100, " + "location=n o, menubar=no, resizable=no, " +
"scrollbars =no, titlebar=no, toolbar=no", true);

I know that in my PageLoad() method, I could add an Onclick() method to a hyperlink, using the .

But I don't want to do a roundtrip every time the user clicks an entry in the listbox.

So is there some way a hyperlink button could, in the code-behind put a
javascript command into the html re-emited to the user?

Thanks!


Nov 18 '05 #5

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

Similar topics

3
2096
by: Volker Hetzer | last post by:
Hi! I'm new to javascript and I'd like to know whether javascript can process javascript-code entered by the user or read from a file. We've got an application that uses ActiveX as main customization means and we'd like to write a javascript control which listens to a socket, reads a javascript statement accessing some ActiveX classes and...
6
2256
by: Vanitha | last post by:
Hi All, I am developing a Web based application for an embedded target, using BOA webserver. I need to return some values to the HTML client. I am using CGI-C to extract the values sent by the client from the server. I dont want to generate the entire HTML page each time from the server.'cos i need to refresh the status less than a...
2
2647
by: John Owens | last post by:
I use in Render( HtmlTextWriter output) : //-------------------------------------------------------------------------- output.WriteBeginTag( "a" ); if( ID != null ) output.WriteAttribute( "id", ClientID );
7
3567
by: Venus | last post by:
Hello, I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows Build up the string that is placed somewhere in the HTML code the same way like regular input fields can. strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf strForm += "<asp:button name=""myName"" .......
1
2204
by: Merennulli | last post by:
Ok, did some seriously ugly meddling with javascript so that my user can do a level of formatting which gets shunted into a hidden input field as raw HTML code. That code is then passed back and written directly to a file. This works..almost. Problems: 70% of the time, when I click the "Create" asp:button object to activate the script, the...
3
2014
by: Sandman | last post by:
Hello, I'm building a website in PHP and Javascript. The registration portion is divided into 2 sections: 1. In one, I get info about the visitor. This is sent via POST to a php script which is section 2. 2. In the second section, I get some specific information about their pets and make suggestions. I'm having problems with section 2, and I...
14
4727
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
0
25922
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. The key point is that you need to start the random number generator with a seed. Doing it in the form load with the number of milliseconds since...
5
2207
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div, etc.). It is used as follows: addElementToPage("writeroot", "input", "type:button, text:testText, value:testvalue, onclick:test1") The first...
2
37673
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side functionality in the user's browser without having to make calls back to the server; thus, saving resources. The following example demonstrates how...
0
7605
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...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
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...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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...

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.