473,473 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page.RegisterClientScriptBlock

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.
Nov 19 '05 #1
2 4596
Do like this,

string NoAccess = " <script language='javascript'> "+
" 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").C lick();

Hope, this helps.
--
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com... 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.

Nov 19 '05 #2
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" wrote:
Do like this,

string NoAccess = " <script language='javascript'> "+
" 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").C lick();

Hope, this helps.
--
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
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.


Nov 19 '05 #3

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

Similar topics

3
by: Mike P | last post by:
Is there a difference between Page.RegisterClientScriptBlock and Page.RegisterStartupScript? I've seen them both in code examples and they both seem to be doing the same thing. Any help would...
1
by: John Livermore | last post by:
I have a user control that can be created from a variety of other user controls. It is the same no matter where it is created from, and I only want one instance of it on the page. Is there a...
2
by: Earl Teigrob | last post by:
I have a Web Custom Control that builds javascript to write to the page. The DatePickerJs() function builds over 500 lines of javacript code. Even thought my Custom Web Control does not write it to...
3
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary...
9
by: Nathan Sokalski | last post by:
I have used the RegisterClientScriptBlock method in external functions of mine (ones that are saved in a separate *.vb file), where I use them as follows: Public Shared Sub MyFunction(ByVal...
4
by: Mori | last post by:
I am using masterPage and I need to populate a textbox that is in a content control with data from popup page that is not part of the master page. This code works if no masterpage is involved. ...
2
by: Keithb | last post by:
My application has several check boxes included one labeled "All" and another labeled "None." How can I incorporate javascript that will detect that the "All" or "None" checkbox was changed and...
1
by: ruca | last post by:
Hi, I have a button that when clicked must print the current page after doing something in a certain function. For that I have this code: ...
8
by: =?Utf-8?B?UGF1bCBSZWVk?= | last post by:
Hello, I have an app that was xcopy deployed from an ASP.NET 1.1 W2KServer to a box running ASP.NET 2.0 W2003Server. The app runs fine with the exception of where I use the above method. It...
0
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...
0
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
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...

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.