Hi,
I have created a Visual Web Part suing Visual Studio 2012. The web part contains a button, on click event of the same I validate the input using inline jquery and then if it is valid, then it calls the server side Button_Click event in .ascx.cs file.
When I deploy and run using Visual Studio, web part works fine, but when I create .wsp using TFS build script and deploy, then it throws Null Reference Exception, when I click on the button in my Web Part.
I have put the following code:
namespace MyReportsWebPart
{
[ToolboxItemAttribute(false)]
public class ReportsWP : Microsoft.SharePoint.WebPartPages.WebPart
{
ReportsWPUserControl control;
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/ReportsWebPart/ReportsWP/ReportsWPUserControl.ascx";
protected override void CreateChildControls()
{
control = Page.LoadControl(_ascxPath) as ReportsWPUserControl;
if (control != null)
{
control.ReportsWebPart = this;
Controls.Add(control);
}
}
protected override void OnInit(EventArgs e)
{
EnsureChildControls();
base.OnInit(e);
}
}
}
.ascx file:
<div><asp:Button ID="btnGenerateReport" Text="Generate Report" runat="server" OnClick="btnGenerateReport_Click" OnClientClick="return ValidateInput();" />
</div>
.ascx.cs file:
namespace MyReportsWebPart
{
public partial class ReportsWPUserControl : UserControl
{
public ReportsWP ReportsWebPart { get; set; }
protected void btnGenerateReport_Click(object sender, EventArgs e)
{
//Some code
}
}
Abhijit Sil