I have green underline when i use "RegisterStartupScript"in login page, the message told me that (
"Warning 6 'System.Web.UI.Page.RegisterStartupScript(string, string)' is obsolete: '"The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202"'
C:\Users\mkf\documents\visual studio 2010\projects\WebApplication23\WebApplication23\login.aspx.cs 43 17 WebApplication23 )
So how can fix this problem??????
Page Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
string userName = txtName.Text;
string pass = txtPass.Text;
string sqlSel = "select * from userRegister where username=@name and userPass=@pass";
if (operateData.login(sqlSel, userName, pass))
{
Session["userName"] = txtName.Text;
string sql = "select * from userRegister where userName='" + Session["userName"] + "'";
SqlDataReader sdr = operateData.getRow(sql);
sdr.Read();
if (Convert.ToBoolean(sdr["lock"]))
{
Session["userName"] = null;
RegisterStartupScript("true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>");
}
else
RegisterStartupScript("true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>");
}
else
{
RegisterStartupScript("false", "<script>alert('User name or password is incorrect!')</script>");
}
}
}
Client.RegisterStartupScript(typeof(page),"NameForScript","<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>", true);
Sorry I was just giving an example of the syntax. Cliient.registerstarupscript(type,name for script,script, generate code) Type = this is always typeof(page) or Me.gettype() Name for script = a unique name for script input type string Script = script goes here
as string Generate code = this is Boolean and tells the method to place the code in the HTML markup I think hehe. I always set it to true Google client.registerstartupscript site: msdn.com Microsoft has a full write up on syntax and parameters. It's pretty
straight forward. You'll need to modify all of your calls to match this syntax.
The method, Page.RegisterStartupScript is obsolete, as the error says. And again, as the message already said, the recommended alternative is to use ClientScript.RegisterStartupScript. Replace all the Page.RegisterStartupScript
lines with ClientScript.RegisterStartupScript.
Can you please explane that in my code(can you change my code above for the new one) I gote some error when I change it to ClientScriptManager.RegisterStartupScript()
RegisterStartupScript("true","<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>");
as
ClientScriptManager.RegisterStartupScript(this.GetType(), "true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>");
mkf
RegisterStartupScript("false","<script>alert('User name or password is incorrect!')</script>");
as
ClientScriptManager.RegisterStartupScript(this.GetType(), "false", "<script>alert('User name or password is incorrect!')</script>");
Thanks for Replay, I still have error when i replace it with new code???? The error"Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.ClientScriptManager.RegisterStartupScript(System.Type, string, string)' C:\Users\mkf\Documents\Visual Studio
2010\WebSites\WebSite1\login.aspx.cs 43 17 C:\...\WebSite1\"
The error "Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.ClientScriptManager.RegisterStartupScript(System.Type, string, string)' C:\Users\mkf\Documents\Visual Studio 2010\WebSites\WebSite1\login.aspx.cs
43 17 C:\...\WebSite1\"
According to the description above, please modify your code as follows:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
string userName = txtName.Text;
string pass = txtPass.Text;
string sqlSel = "select * from userRegister where username=@name and userPass=@pass";
if (operateData.login(sqlSel, userName, pass))
{
Session["userName"] = txtName.Text;
string sql = "select * from userRegister where userName='" + Session["userName"] + "'";
SqlDataReader sdr = operateData.getRow(sql);
sdr.Read();
if (Convert.ToBoolean(sdr["lock"]))
{
Session["userName"] = null;
cs.RegisterStartupScript(this.GetType(), "true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>");
}
else
cs.RegisterStartupScript(this.GetType(), "true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>"); }
else
{
cs.RegisterStartupScript(this.GetType(), "false", "<script>alert('User name or password is incorrect!')</script>");
}
}
}
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
mkf
Member
7 Points
54 Posts
How Can Fix "RegisterStartupScript" error
Apr 27, 2012 08:41 PM|LINK
I have green underline when i use "RegisterStartupScript" in login page, the message told me that ( "Warning 6 'System.Web.UI.Page.RegisterStartupScript(string, string)' is obsolete: '"The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202"' C:\Users\mkf\documents\visual studio 2010\projects\WebApplication23\WebApplication23\login.aspx.cs 43 17 WebApplication23 )
So how can fix this problem??????
Page Code
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) { string userName = txtName.Text; string pass = txtPass.Text; string sqlSel = "select * from userRegister where username=@name and userPass=@pass"; if (operateData.login(sqlSel, userName, pass)) { Session["userName"] = txtName.Text; string sql = "select * from userRegister where userName='" + Session["userName"] + "'"; SqlDataReader sdr = operateData.getRow(sql); sdr.Read(); if (Convert.ToBoolean(sdr["lock"])) { Session["userName"] = null; RegisterStartupScript("true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>"); } else RegisterStartupScript("true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>"); } else { RegisterStartupScript("false", "<script>alert('User name or password is incorrect!')</script>"); } } }Loganix77
Participant
1351 Points
412 Posts
Re: How Can Fix "RegisterStartupScript" error
Apr 27, 2012 09:11 PM|LINK
Client.RegisterStartupScript(typeof(page),"NameForScript", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>", true);
mkf
Member
7 Points
54 Posts
Re: How Can Fix "RegisterStartupScript" error
Apr 27, 2012 09:56 PM|LINK
Is this for just the successful Login part below ???
else RegisterStartupScript("true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>"); }Or fo All part
RegisterStartupScript("true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>"); } else RegisterStartupScript("true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>"); } else { RegisterStartupScript("false", "<script>alert('User name or password is incorrect!')</script>"); }Loganix77
Participant
1351 Points
412 Posts
Re: How Can Fix "RegisterStartupScript" error
Apr 28, 2012 12:06 AM|LINK
Ruchira
All-Star
43038 Points
7031 Posts
MVP
Re: How Can Fix "RegisterStartupScript" error
Apr 28, 2012 10:56 AM|LINK
Hello,
The method, Page.RegisterStartupScript is obsolete, as the error says. And again, as the message already said, the recommended alternative is to use ClientScript.RegisterStartupScript. Replace all the Page.RegisterStartupScript lines with ClientScript.RegisterStartupScript.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.mkf
Member
7 Points
54 Posts
Re: How Can Fix "RegisterStartupScript" error
Apr 28, 2012 11:03 AM|LINK
Can you please explane that in my code(can you change my code above for the new one) I gote some error when I change it to ClientScriptManager.RegisterStartupScript()
Ruchira
All-Star
43038 Points
7031 Posts
MVP
Re: How Can Fix "RegisterStartupScript" error
Apr 28, 2012 11:09 AM|LINK
Hi,
Here you go
as
ClientScriptManager.RegisterStartupScript(this.GetType(), "true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>");as
ClientScriptManager.RegisterStartupScript(this.GetType(), "true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>");as
ClientScriptManager.RegisterStartupScript(this.GetType(), "false", "<script>alert('User name or password is incorrect!')</script>");
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.mkf
Member
7 Points
54 Posts
Re: How Can Fix "RegisterStartupScript" error
Apr 28, 2012 12:34 PM|LINK
Thanks for Replay, I still have error when i replace it with new code???? The error "Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.ClientScriptManager.RegisterStartupScript(System.Type, string, string)' C:\Users\mkf\Documents\Visual Studio 2010\WebSites\WebSite1\login.aspx.cs 43 17 C:\...\WebSite1\"
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: How Can Fix "RegisterStartupScript" error
May 02, 2012 08:14 AM|LINK
Hi mkf,
According to the description above, please modify your code as follows:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) { ClientScriptManager cs = Page.ClientScript; string userName = txtName.Text; string pass = txtPass.Text; string sqlSel = "select * from userRegister where username=@name and userPass=@pass"; if (operateData.login(sqlSel, userName, pass)) { Session["userName"] = txtName.Text; string sql = "select * from userRegister where userName='" + Session["userName"] + "'"; SqlDataReader sdr = operateData.getRow(sql); sdr.Read(); if (Convert.ToBoolean(sdr["lock"])) { Session["userName"] = null; cs.RegisterStartupScript(this.GetType(), "true", "<script>alert('" + sdr["lockCause"].ToString() + "');location='index.aspx'</script>"); } else cs.RegisterStartupScript(this.GetType(), "true", "<script>alert('Login is successful!Click to return Home');location='index.aspx'</script>"); } else { cs.RegisterStartupScript(this.GetType(), "false", "<script>alert('User name or password is incorrect!')</script>"); } } }Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
mkf
Member
7 Points
54 Posts
Re: How Can Fix "RegisterStartupScript" error
May 02, 2012 06:03 PM|LINK
Great, Thanks Catherine its work