EDIT: LÖSNINGEN PÅ DETTA PROBLEM FINNS I DENNA TRÅD: [två page_load på en och samma sida (C#)] Hej, du skulle kunna bygga upp det så här. Har testat en massa nu men får det inte att fungera. Förstår inte riktigt. Johan, Nä, jag förstår verkligen inte.already defines a member called 'Page_Load' with the same parameter types
Har två page_load. men verkar som man inte får ha det, hur skall jag göra?
Om jag bara kör ett av scripten funkar det.
<code>
<script runat = "server">
private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindGrid();
}
private void BindGrid()
{
DataTable table = new DataTable("Users");
table.Columns.Add("firstName");
table.Columns.Add("lastName");
table.Columns.Add("emailAddress");
AddRow(table, "Bugs", "Bunny", "bbunny@wb.com");
AddRow(table, "Mickey", "Mouse", "mmouse@disney.com");
AddRow(table, "Donald", "Duck", "dduck@disney.com");
AddRow(table, "Dan", "Marino", "dmarino@dolphins.com");
AddRow(table, "Steve", "Stchur", "sstchur@yahoo.com");
myGrid.DataSource = new DataView(table);
myGrid.DataBind();
}
private void AddRow(DataTable table, string firstName,
string lastName, string email)
{
DataRow row = table.NewRow();
row["firstName"] = firstName;
row["lastName"] = lastName;
row["emailAddress"] = email;
table.Rows.Add(row);
}
</script>
<script runat="server">
private void Page_Load(object Source, EventArgs e){
HttpBrowserCapabilities bc = Request.Browser;
If bc.Browser = "IE" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_ie.css'>");
} ElseIf bc.Browser = "Netscape" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_netscape.css'>");
} ElseIf bc.Browser = "Opera" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_opera.css'>");
}
}
</script>
</code>Sv: already defines a member called 'Page_Load' with the same parameter types
Private void Page_Load(object sender, EventArgs e)
{
// ex.kollar PostBack mm.
MySubOne();
MySubTwo();
}
Private void MySubOne()
{
// Lite kod.
}
Private void MySubTwo() {
// Lite mera kod.
}
/m
Sv:already defines a member called 'Page_Load' with the same parameter types
Sv: already defines a member called 'Page_Load' with the same parameter types
Vad är det du inte förstår?
Du har en Page_Load, Sen kan du ha hur många olika "subar", med olika namn.
I Page_Load så skriver du SubensNamn(); så körs den suben.
/mSv:already defines a member called 'Page_Load' with the same parameter types
Nu får jag detta felmeddelande:
CS1520: Class, struct, or interface method must have a return type
Line 16: MySubOne(object sender, EventArgs e)
Koden:
<code>
<script runat = "server">
private void Page_Load(object sender, EventArgs e)
{
MySubOne();
MySubTwo();
}
Private void MySubOne(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindGrid();
}
Private void MySubTwo(object Source, EventArgs e) {
HttpBrowserCapabilities bc = Request.Browser;
If bc.Browser = "IE" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_ie.css'>");
} ElseIf bc.Browser = "Netscape" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_netscape.css'>");
} ElseIf bc.Browser = "Opera" {
css1.Text = ("<LINK rel='stylesheet' type='text/css' href='css_opera.css'>");
}
}
private void BindGrid()
{
DataTable table = new DataTable("Users");
table.Columns.Add("firstName");
table.Columns.Add("lastName");
table.Columns.Add("emailAddress");
AddRow(table, "Bugs", "Bunny", "bbunny@wb.com");
AddRow(table, "Mickey", "Mouse", "mmouse@disney.com");
AddRow(table, "Donald", "Duck", "dduck@disney.com");
AddRow(table, "Dan", "Marino", "dmarino@dolphins.com");
AddRow(table, "Steve", "Stchur", "sstchur@yahoo.com");
myGrid.DataSource = new DataView(table);
myGrid.DataBind();
}
private void AddRow(DataTable table, string firstName,
string lastName, string email)
{
DataRow row = table.NewRow();
row["firstName"] = firstName;
row["lastName"] = lastName;
row["emailAddress"] = email;
table.Rows.Add(row);
}
</script>
</code>