[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

RegisterStartupScript written in a button click server event not working.

swapna.munukoti

4/23/2007 1:28:00 PM

Hi all,

To my knowledge we can execute the javascript any where using
RegisterStartupScript method. I have written the same javascript code
in button click event and tried to execute using RegisterStartupScript
metod in a composite custom control. I have written code to open
another aspx page in that javascript.

It didnt opened the page. But when debugging the code, it was going
thru that code.

If i execute the samne code using addattribute to that button control,
its displaying the page as expected.

Am I missing some thing.

Here is the code I was trying to execute:
void ctrlButton_Click(object sender, EventArgs e)
{
string strButtonClickScript = "javascript:var WinSettings
= 'center:yes;resizable:no;dialogHeight:300px'; ";
strButtonClickScript = strButtonClickScript + "var ParmA
=''; ";
strButtonClickScript = strButtonClickScript +
"window.showModalDialog('http://localhost:4620/WebSite8/
Default3.aspx', ParmA, WinSettings)";
Page.ClientScript.RegisterStartupScript(this.GetType(),
scriptKey, strButtonClickScript);
}
The code thatz working:
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type,
"ctrlButton");
writer.AddAttribute("language", "javascript");
string strButtonClickScript = "javascript:var WinSettings =
'center:yes;resizable:no;dialogHeight:300px'; ";
strButtonClickScript = strButtonClickScript + "var ParmA
=''; ";
strButtonClickScript = strButtonClickScript +
"window.showModalDialog('http://localhost:4620/WebSite8/
Default3.aspx', ParmA, WinSettings)";
writer.AddAttribute("onclick", strButtonClickScript);
}


Thanks in Advance,
Swapna.

2 Answers

Sergey Poberezovskiy

5/16/2007 2:27:00 AM

0

swapna,

In the first example, you register the javascript and it should appear on
your page - you can check that by viewing the page source in the browser.
A few points worth mentioning here:
- if you just need to open a modal dialog - there is no need to make a
round trip to the server, and you will want to employ your working example
(attaching javascript to button client click)
- if you need to visit your server (say for validation; to get some
parameters based on the user input, etc), then you will need to correct your
server-side code:
- in strButtonClickScript - remove "javascript:" at the start of the string
- in RegisterStartupScript add fourth parameter (true) to wrap your
javascript in "script" tags, so that the browser can read it

HTH

"swapna.munukoti@gmail.com" wrote:

> Hi all,
>
> To my knowledge we can execute the javascript any where using
> RegisterStartupScript method. I have written the same javascript code
> in button click event and tried to execute using RegisterStartupScript
> metod in a composite custom control. I have written code to open
> another aspx page in that javascript.
>
> It didnt opened the page. But when debugging the code, it was going
> thru that code.
>
> If i execute the samne code using addattribute to that button control,
> its displaying the page as expected.
>
> Am I missing some thing.
>
> Here is the code I was trying to execute:
> void ctrlButton_Click(object sender, EventArgs e)
> {
> string strButtonClickScript = "javascript:var WinSettings
> = 'center:yes;resizable:no;dialogHeight:300px'; ";
> strButtonClickScript = strButtonClickScript + "var ParmA
> =''; ";
> strButtonClickScript = strButtonClickScript +
> "window.showModalDialog('http://localhost:4620/WebSite8/
> Default3.aspx', ParmA, WinSettings)";
> Page.ClientScript.RegisterStartupScript(this.GetType(),
> scriptKey, strButtonClickScript);
> }
> The code thatz working:
> protected override void AddAttributesToRender(HtmlTextWriter writer)
> {
> writer.AddAttribute(HtmlTextWriterAttribute.Type,
> "ctrlButton");
> writer.AddAttribute("language", "javascript");
> string strButtonClickScript = "javascript:var WinSettings =
> 'center:yes;resizable:no;dialogHeight:300px'; ";
> strButtonClickScript = strButtonClickScript + "var ParmA
> =''; ";
> strButtonClickScript = strButtonClickScript +
> "window.showModalDialog('http://localhost:4620/WebSite8/
> Default3.aspx', ParmA, WinSettings)";
> writer.AddAttribute("onclick", strButtonClickScript);
> }
>
>
> Thanks in Advance,
> Swapna.
>
>

msb

11/8/2013 1:55:00 AM

0


"Calvin"
>>> 10 Brian May was the lead guitarist for which British rock band?

Erland Sommarskog:
>> Queen. (You're including a rock'n'roll question that even Mark Brader
>> may be able to answer?)
>
> As it turns out, no.

No, but I had at least heard of the guy.
--
Mark Brader, Toronto, msb@vex.net
Irving Thalberg's advice on GONE WITH THE WIND:
"Forget it, Louis. No Civil War picture ever made a nickel."