Visual Studio 2010 and Artisteer


Author Message
Gábor

Posted: 4/18/2011
Quote message 

Dear All,

I made a success export to Visual Studio 2010. When I open the export in Visual Studio as website, the default page working fine.

I made a new asp component on the default.aspx page (for example: Label) in an artisteer:Article:

1 artisteer:Article
2 ContentTemplate
3 Label
4 ...


And I would like set the label's text property in the default.aspx.cs file:

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "OK";
}

...

I will have the following error:
"The name 'Label1' does not exist in the current context"


It is working only, if the Label is outside the artisteer:Article:
1 Label
2 artisteer:Article
3 ContentTemplate
4 ...

In this case I can't use programmatically the Article and Box elements of the design.

Could you help me what would be the solution?

Thank you

 
Steven Webster

Posted: 4/20/2011
Quote message 

Assuming you've created your files in Artisteer and exported for a Visual Studio Project....then your code behind should look something like this

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;

public partial class DefaultHeader : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "something goes here";
}
}

I just test it and was able to define the test of a lable control in the header placeholder just fine. I"m using Artisteer 3.0 RC1

 
Kathy

Posted: 4/26/2011
Quote message 

I'm using Artisteer 2.6 for Windows. It doesn't work for me either.
Where can I download Artisteer 3.0 RC1 ?


 
Sorry

Posted: 4/26/2011
Quote message 

Quote Kathy:

I'm using Artisteer 2.6 for Windows. It doesn't work for me either.
Where can I download Artisteer 3.0 RC1 ?




DUH. Who know? How do you even know to use a computer?
 
Henry

Posted: 4/27/2011
Quote message 

I have the same problem. I copyed Artisteer generated .NET project files into my .net project. I try to use the block to wrap around my controls. I got control does not exist in the current context error message. What is the correct way of using Artisteer design in my existing project? Do I need to add anything in web.config?
 
Frank

Posted: 5/10/2011
Quote message 

Same problem here. I exported a ASP.NET project from Artisteer, and added a TextBox inside <artisteer:Block>, when I try to use the TextBox in the Page_Load(), I got the following error: "The name 'TextBox1' does not exist in the current context". Can anybody share why it is happening?

 
Roberto Gammino

Posted: 5/11/2011
Quote message 

protected void Page_Load(object sender, EventArgs e)
{
//a fast, but I do not remember if in search nested controls.
Label mylabel = (Label) FindControl("Label1");
if (mylabel == null) throw new NotImplementedException();
mylabel.Text = "OK";
}

/// <summary>
/// This is a recursive method instead.
/// Able to search your control nested inside other controls.
/// I wrote it quickly for you and I have not had time to do a test, but it should work.
/// </summary>
/// <param name="controlParent"></param>
/// <param name="controlId"></param>
/// <returns></returns>
protected Control FindMyControl(Control controlParent, string controlId)
{
string toSearch = controlId.ToLower();
Control result = null;

foreach (Control ControlInParent in controlParent.Controls)
{
if (string.Compare(controlParent.ID.ToLower(), toSearch) == 0)
{
result = ControlInParent;
}
else if(ControlInParent.HasControls())
{
result = FindMyControl(ControlInParent, controlId);
}

if(result != null)
{
break;
}
}
return result;
}

public void Test_FindMyControl()
{
//
//test the method: FindMyControl
//
Label myLabel = null;
Control control = FindMyControl(Article1, "Label1");
if(control != null) myLabel = (Label) control;
if (myLabel != null) myLabel.Text = "OK";
}
 
Vlad

Posted: 5/12/2011
Quote message 

Please note that Article (or Block) is templated control.
So you cannot refer to controls inside ContentTemplate directly from page.
You should find this control within Article's context.

Try to add the following code to the Article class

public override Control FindControl(string id)
{
EnsureChildControls();
if (null != _contentPlaceholder && _contentPlaceholder.Controls[0] is TemplateContainer)
return _contentPlaceholder.Controls[0].FindControl(id);

return null;
}

and then you can refer to your controls via
Label ctl = Article1.FindControl("Label1") as Label;
 
Kathy

Posted: 5/20/2011
Quote message 

This is how I fixed it:

<artisteer:Block ID="LogonBlock" Caption="User Logon" runat="server">
<ContentTemplate>
<div> <table width="100%" bgcolor="#E2EAEE" cellpadding="2" cellspacing="2" border="0" align="center">

<tr >
<td>
User Name:</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtUserName" runat="server" Width="120"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td></tr>
<tr>
<td>
<asp:TextBox ID="txtPassword" runat="server" Width="120" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>
<span class="art-button-wrapper">
<span class="l"> </span>
<span class="r"> </span>
<asp:Button ID="btnLogon" class="art-button" OnClick="btnLogon_Click" runat="server" Text="Logon" />
</span>

</td>
</tr>
</table>
</div>
</ContentTemplate>
</artisteer:Block>


protected void Page_Load(object sender, EventArgs e)
{
LogonBlock.DataBind();
}

protected void btnLogon_Click(object sender, EventArgs e)
{
TextBox txtUserName = LogonBlock.ContentPlaceholder.Controls[0].FindControl("txtUserName") as TextBox;
TextBox txtPassword = LogonBlock.ContentPlaceholder.Controls[0].FindControl("txtPassword") as TextBox;
ValidateUser(txtUserName.Text, txtPassword.Text);
}
 
René

Posted: 4/19/2012
Quote message 

Quote Steven Webster:

Assuming you've created your files in Artisteer and exported for a Visual Studio Project....then your code behind should look something like this

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;

public partial class DefaultHeader : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "something goes here";
}
}

I just test it and was able to define the test of a lable control in the header placeholder just fine. I"m using Artisteer 3.0 RC1



Hi, I am really new in the combination of Artisteer and Visual Studio. How do i open the export from Artisteer in Visual Studio? Do i need to create some kind of project?