PDA

View Full Version : [CLOSED] Error when assign datasource to store in user control



redi
Dec 12, 2013, 6:49 AM
Hai Everyone..

I have little problem here. I have parent page let says A.aspx, and i have user control let says B.ascx. In Page A.aspx i call web service to get dataset, when i get it, i want to parsing to User Control B. I create some method in User Control B to store a dataset to combobox store. When i debug the User control page, i get error that says "Object reference not set to an instance of object.". Please look my attachment image on above.

This is my function in user control page :


Public Sub storeDataToCombo(ByVal ds As DataSet)

Try

Me.storeRole.DataSource = ds.Tables(2)
Me.storeRole.DataBind()
Catch ex As Exception

End Try

End Sub


And this is method from parent page :


Public Sub CreateUser_Click(ByVal sender As Object, ByVal e As DirectEventArgs) Handles CreateUser.Click
Dim dsDropDown As New DataSet

extHelper.setUserControlContent(Window1, "ctrl_UserManagerWindowForm.ascx", Me.Form)

dsDropDown = BLM.blGetDropDown(Me.Session("AuthState"))

ctrl_FormInput.storeDataToCombo(dsDropDown)

Window1.Show()

'X.Js.Call("createWindow")

End Sub



Thanks for your attention. :)

Daniil
Dec 12, 2013, 7:59 AM
Hi @redi,

Please clarify what exactly statement does cause the NullReferenceException?

redi
Dec 12, 2013, 8:20 AM
Hi @redi,

Please clarify what exactly statement does cause the NullReferenceException?

Hi @Daniil,

THanks for reply my question.The statement has showed when i try to assign store of combo box from dataset in code behind


Me.storeRole.DataSource = ds.Tables(2)

Daniil
Dec 12, 2013, 2:10 PM
So, is "ds" null?

I don't get the entire scenario. Could you, please, provide a full test case to reproduce?

redi
Dec 13, 2013, 3:08 AM
So, is "ds" null?

I don't get the entire scenario. Could you, please, provide a full test case to reproduce?

no the ds not null when i check it in debug mode. the ds return the dataset.

i confused because i thing the element store is not recognize in user control. I have little testing, i change my function on my user control page to set value of my ext TextField. This is the code :


Public Sub storeDataToCombo(ByVal ds As DataSet)

Try
'error in here
'Label1.Text = "TESTING"
txtCompleteName.Value = "TESTING" << this is ext:TextField
'Me.storeRole.DataSource = ds.Tables(2)
'Me.storeRole.DataBind()
Catch ex As Exception

End Try

End Sub

And this is my markup syntax of my user control page :


<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ctrl_UserManagerWindowForm.ascx.vb" Inherits="UIFMS.ctrl_UserManagerWindowForm" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<ext:FormPanel ID="FormPanel1" runat="server"
Margins="5 5 5 5" Region="Center"
Frame="true" ButtonAlign="Center" Layout="FormLayout">
<Defaults>
<ext:Parameter Name="LabelWidth" Value="200" Mode="Raw" />
</Defaults>
<Items>
<ext:FieldSet runat="server" Title="User Infromation" Layout="FormLayout">

<Items>
<ext:TextField ID="txtUserID" runat="server" Name="UserID" FieldLabel="User ID" Width="300" AllowBlank="false" />
<ext:TextField ID="txtCompleteName" runat="server" Name="CompleteName" FieldLabel="Complete Name" Width="300" AllowBlank="false" />
<ext:TextField ID="txtPassword" runat="server" InputType="Password" Name="Password" FieldLabel="Password" Width="300" />
<ext:TextField ID="txtConfirmPass" runat="server" InputType="Password" Name="ConfirmPassword" FieldLabel="Confirm Password" Width="300" />
<ext:Checkbox ID="chkActive" runat="server" Name="Active" FieldLabel="Active" />

</Items>

</ext:FieldSet>
<ext:FieldSet runat="server" Title="User Authorization" Layout="FormLayout">
<Items>
<ext:ComboBox runat="server" ID="ComboBox1" FieldLabel="Role" DisplayField="RoleDesc" ValueField="RoleID" Width="200" TypeAhead="false">
<Store>
<ext:Store runat="server" ID="storeRole">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="RoleID" />
<ext:ModelField Name="RoleDesc" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:FieldSet>
<ext:FieldSet runat="server" Title="Button Action" Layout="FormLayout" Padding="5">
<Items>
<ext:Toolbar ID="Toolbar1"
runat="server"
Flex="1"
Flat="true">
<Items>
<ext:Button ID="Button1" runat="server" Text="Reset Password" Icon="Reload" />
</Items>
</ext:Toolbar>
</Items>
</ext:FieldSet>
</Items>
<Buttons>
<ext:Button ID="btnSave" runat="server" Icon="Disk" Text="Save">
<DirectEvents>
<Click OnEvent="btnSave_Click">
<EventMask ShowMask="true" Msg="Processing..." MinDelay="500"/>
<ExtraParams>
<ext:Parameter Name="formParam" Value="Ext.encode(#{FormPanel1}.getForm().getValues(false , false, false, true))" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="btnCancle" runat="server" Icon="Cancel" Text="Cancel">
<Listeners>
<Click Handler="#{Window1}.hide()" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>


when i try to debugging again, then show me same error like before. This is my screen capture of error :
7366

and when i try hover my mouse to TextField, the tooltips say is Nothing as well as my store element. Are you any suggestion about my problem ?
Sorry if my english not well.. :)

Daniil
Dec 13, 2013, 11:56 AM
Thank you for the details.

Well, it looks you don't recreate the user control during a DirectEvent.

This line:

ctrl_FormInput.storeDataToCombo(dsDropDown)

Where is the ctrl_FormInput defined?

A full test case to reproduce the problem is appreciated.

redi
Dec 16, 2013, 2:32 AM
Thank you for the details.

Well, it looks you don't recreate the user control during a DirectEvent.

This line:

ctrl_FormInput.storeDataToCombo(dsDropDown)

Where is the ctrl_FormInput defined?

A full test case to reproduce the problem is appreciated.

Hi Daniil...

Thanks for you reply.

the line :

ctrl_FormInput.storeDataToCombo(dsDropDown)
is from the parent aspx page. I defined in my top codebehind of my aspx parent page, this is the code :


Public Class frm_UserManager
Inherits System.Web.UI.Page
Private X As New X
Private BL As New BLFMS.cAuth
Private BLM As New BLFMS.cMasterData
Private extHelper As New cExtHelper
Private ctrl_FormInput As New ctrl_UserManagerWindowForm


if i do a DirectEvent method the user controller must be declare in the function of DirectEvent ?

Daniil
Dec 16, 2013, 4:47 AM
if i do a DirectEvent method the user controller must be declare in the function of DirectEvent ?

Sorry, I don't quite understand the question.

A full and simplified test case demonstrating the whole scenario and reproducing the problem is appreciated.

redi
Dec 18, 2013, 2:59 AM
Hi Daniil..

I think u can closed this thread. I just change my code about this problem and i think thats work.

Thanks for your support and reply Daniil..