Page.RegisterClientScriptBlock

G

Guest

Hi,

I have written this code, but I have received an error message for the
javascript code.

This is written in the html of the page.
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

The C# code:
string NoAccess = " <script language='javascript'> "+
" document.getElementById("NoAccessAllowed").click(); "+
"</script> ";

Page.RegisterClientScriptBlock("NoAccess ", NoAccess );

Is there an error that I am missing ?
TIA
Andrew.
 
V

Vadivel Kumar

Do like this,

string NoAccess = said:
" document.Forms[0].getElementById("NoAccessAllowed").click(); "+
"</script> ";

You can give your formname also, for example your form name is "Form1" then
document.Form1.getElementById("NoAccessAllowed").Click();

Hope, this helps.
 
G

Guest

Hi,

Thanks for your reply.

I have tried your code snipplet, but I got this error. "Object doesn't
support this property or method". Why do I get an error for this line:
document.Forms1.getElementById("NoAccessAllowed").click();

I have tried substituting the Form1 with Form(0) but I still get the same
error.

Another question: I noticed that the debugger will run thru the whole event
for my button e.g. btnFinish() { ... } , before launching the javascript
code. I would like to put some c# code in the event as well to do some
processing. e.g.
If I put an alert javascript code ....

private void btnFinish(system....., event e ....) {

string NoAccess = " <script language='javascript'>
bool a = (alert( " Click OK to Finish, Cancel to return"))
if (a = true) then
document.getElementById("NoAccessAllowed").click();
else
return false;
</script> "
Page.RegisterClientScriptBlock("NoAccess ", NoAccess )

string strSQL = "insert into db_Student (x, y) values (x, y)"
blah blah...
}

HTML codebehind:
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

Q: Will this C# code insert into the db table only if alert a = true ? or
will it do that everytime this event is triggered ?

TIA. cheers.

Vadivel Kumar said:
Do like this,

string NoAccess = said:
" document.Forms[0].getElementById("NoAccessAllowed").click(); "+
"</script> ";

You can give your formname also, for example your form name is "Form1" then
document.Form1.getElementById("NoAccessAllowed").Click();

Hope, this helps.


--
Vadivel Kumar
http://blogs.wdevs.com/varahe

Andrew said:
Hi,

I have written this code, but I have received an error message for the
javascript code.

This is written in the html of the page.
<a href="default.aspx" id="NoAccessAllowed" target="_parent"
type="hidden"></a>

The C# code:
string NoAccess = " <script language='javascript'> "+
" document.getElementById("NoAccessAllowed").click(); "+
"</script> ";

Page.RegisterClientScriptBlock("NoAccess ", NoAccess );

Is there an error that I am missing ?
TIA
Andrew.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top