I have a C# project and I am trying to convert it to ASP.NET and C#. This is my first ASP.NET project.
My users have really liked my former project because it is flexible and easy to use. I am trying to duplicate it as much as possible.
I have designed a page called DM_Services.aspx with 3 panels:
- Panel 1 has a search button and several fields for filtering
- Panel 2 has several fields for editing
- Panel 3 has a gridview.
The ultimate goal is that the user can enter the filters and click search to load data in the gridview.
The user can click on a row in the gridview and it will load the fields in panel 2 with the data for viewing and editing.
I have a C# file called SQLControl.cs which I am using to manage data access.
I keep getting an error on that page in the HasException section.
If I use the following line:
ClientScriptManager.RegisterOnSubmitStatement(Me.GetType(), "ConfirmSubmit", exception);
I get the following error:
The name ‘Me’ does not exist in the current context
If I use:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", "alert(exception);", true);
I get the error:
‘Page’ is a type which does not exist in the current context
If I use the following line:
ScriptManager.RegisterStartupScript(This, this.GetType(), Guid.NewGuid().ToString("N"), "alert(exception);", true);
I get this error:
The name ‘This’ does not exist in the current context
And if I use:
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString("N"), "alert(exception);", true);
Then I get this error:
Argument 1: cannot convertfrom ‘Productivity_ASPWeb.SQLControl’ to ‘System.Web.UI.Control’
I am pretty sure I am getting this error because it is in SQLControl.cs which is outside of the page.
So how do I handle the exception then?
public bool HasException(bool Report = false)
{
if (string.IsNullOrEmpty(exception))
return false;
if (Report == true)
ClientScriptManager.RegisterOnSubmitStatement(Me.GetType(), "ConfirmSubmit", exception);
ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", "alert(exception);", true);
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString("N"), "alert(exception);", true);
ScriptManager.RegisterStartupScript(This, this.GetType(), Guid.NewGuid().ToString("N"), "alert(exception);", true);
return true;
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I removed the scriptManager from the SQLControl.cs and changed the code to:
public bool HasException(bool Report = false)
{
if (string.IsNullOrEmpty(exception))
return false;
else
return true;
}
I then put the scriptmanager in the aspx page:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", "alert(exception);", true);
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0