error occurring in script(default.aspx)

Posted by Mcamkumaran under C# on 2/11/2010 | Views : 1210 | Status : [Member] | Replies : 5
<script runat ="server">
Void Page_Load (send)
{
If(Page.IsPostBack())
{
label1.Text="current rating:" ;
}
}
</script>


void -----------> not declared
{,} -----------------> not declared

MuthuKumaran.R
Senior Software Engineer
Techcello
India.



Responses

Posted by: Vuyiswamb on: 2/11/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
try thid

<script runat="server">

v oid Page_Load(object sender, EventArgs e) {
label1.Text="current rating:" ;
}
</script>


as you can see the "V" used for void is lowercase.

Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Mcamkumaran, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/11/2010 [Member] Bronze

Up
0
Down
Do like as follows

<%@ Page Language="C#" %>

<script runat="server">
void Page_Load(object sender, EventArgs e)
{

If(Page.IsPostBack())
{
label1.Text="current rating:" ;
}

}
</script>


Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Mcamkumaran, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/11/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
I would rather go for :

<%@ Page Language="C#" %>


<script runat="server">

void Page_Load(object sender, EventArgs e)
{
If(this.IsPostBack)
{
label1.Text="current rating:" ;
}
}
</script>


See I have used this.IsPostback without braces, as I think it is a property.

Cheers.


www.abhisheksur.com

Mcamkumaran, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 2/11/2010 [Member] Bronze

Up
0
Down
Void is a return type.
You have to declare function in Small letters for "VOID" here Not Void but void
Add See the Arguments,
Page_Load has two arguments
1. Object
2. EventArgs

So your function look like

protected void Page_Load(object sender, EventArgs e)
{

}



Mcamkumaran, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RtpHarry on: 2/12/2010 [Member] [MVP] Bronze

Up
0
Down
Yeah my version would look like this:


<script runat ="server">
void Page_Load (object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
label1.Text="current rating:";
}
}
</script>


- lowercase void
- lowercase if
- no () on IsPostBack

I have also put a negative operator on the postback check because normally you want to set properties on first display and then the label remembers the value in viewstate on postback so no need to set again.

Also you can do it without the Page. in that check because your asp.net page inherits from the Page class and therefore has IsPostBack available as a member property.

UPDATE: For some reason the editor is putting an empty line between each line of code. I am not suggesting formatting it like that.

Mcamkumaran, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response