Showing posts with label passing. Show all posts
Showing posts with label passing. Show all posts

Wednesday, March 28, 2012

LinkButton/DataGrid/HoverMenu Issue - Linkbutton not passing values?

Hello all,
I have a unique situation here, that I have been stumped on for 3 days now. I have a nested master/detail form as seen below, and within the 2nd grid I have an AJAX hovermenu, for some reason I am not able to collect the values of the form when the user wants to insert the values. I am able to capture the linkbutton event in the code behind but, when it gets to the assigning of the textbox value for entry into the DB it is comes up with a reference not set to the instance of an object. The first set of code is the asp.net page the second set is the code behind, any pointers on this would be extremely helpful, and I would owe you like lunch or something :) Thanks again for all of your help.

ASP.Net Code

1<asp:UpdatePanel ID="up0" runat="server" Visible="true">2 <ContentTemplate>3 <asp:GridView4 ID="GridView1"5 runat="server"6 Width="656px"7 CellPadding="4"8 DataSourceID="SqlDataSource1"9 ForeColor="#333333"10 OnRowDataBound="bindMarketControl"11 AutoGenerateColumns="False"12 GridLines="None"13 >14 <Columns>15 <asp:TemplateField>16 <ItemTemplate>17 <h2><%# Eval("MarketName")%></h2>18 <table width="100%">19 <tr>20 <td width="200px">Team Name</td>21 <td width="200px">Head Count</td>22 <td width="200px">Orders</td>23 <td width="200px">Revenue</td>24 </tr>25 </table>26 <asp:UpdatePanel ID="up1" runat="server">27 <ContentTemplate>28 <asp:GridView29 ID="TeamDetail"30 DataSourceID="GetTeamDetailFormView"31 AutoGenerateColumns="False"32 ShowHeader="False"33 GridLines="None"34 runat="server">35 <Columns>36 <asp:TemplateField>3738 <ItemTemplate>39 <asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">40 <div style="border:1px outset white;padding:2px;">41 <div><asp:LinkButton42 ID="LinkButton1"43 runat="server"44 CommandName="Edit"45 Text="Edit"46 /></div>47 <div><asp:LinkButton48 ID="LinkButton2"49 runat="server"50 CommandName="Delete"51 Text="Delete" /></div>52 </div>53 </asp:Panel>54 <asp:Panel ID="Panel9" runat="server">55 <table width="100%">56 <tr>57 <td width="195px">58 <asp:Label59 Font-Bold="true"60 ID="Label0"61 runat="server"62 Text='<%# Eval("TeamName")%>' />63 </td>64 <td width="200px">65 <asp:Label66 ID="Label1"67 runat="server"68 Text='<%# Eval("HeadCount")%>' />69 </td>70 <td width="200px">71 <asp:Label72 ID="Label2"73 runat="server"74 Text='<%# Eval("Orders")%>' />75 </td>76 <td width="200px">77 <asp:Label78 ID="Label3"79 runat="server"80 Text='<%# Eval("Revenue")%>' />81 </td>82 </tr>83 </table>84 </asp:Panel>85 <cc1:HoverMenuExtender ID="hme2"86 HoverCssClass="popupHover"87 PopupControlID="PopupMenu"88 PopupPosition="Left"89 TargetControlID="Panel9"90 PopDelay="25"91 runat="server" />92 </ItemTemplate>93 <EditItemTemplate>94 <asp:Panel ID="Panel9" runat="server" Width="100%">95 <table width="100%">96 <tr>97 <td width="200px">98 <asp:TextBox99 ID="TextBox00"100 runat="server"101 Text='<%# Bind("TeamId")%>'102 Visible="false"103 EnableViewState="true"104 />105 <asp:TextBox106 ReadOnly="true"107 Font-Bold="true"108 ID="TextBox0"109 runat="server"110 Text='<%# Bind("TeamName")%>'111 EnableViewState="true" />112 </td>113 <td width="200px">114 <asp:TextBox115 ID="TextBox1"116 runat="server"117 Text='<%# Bind("HeadCount")%>'118 EnableViewState="true" />119 </td>120 <td width="200px">121 <asp:TextBox122 ID="TextBox2"123 runat="server"124 Text='<%# Bind("Orders")%>'125 EnableViewState="true"126 />127 </td>128 <td width="200px">129 <asp:TextBox130 ID="TextBox3"131 runat="server"132 Text='<%# Bind("Revenue")%>'133 EnableViewState="true" />134 </td>135 </tr>136 </table>137 </asp:Panel>138 <cc1:HoverMenuExtender139 ID="hme1"140 TargetControlID="Panel9"141 PopupControlID="PopupMenu"142 HoverCssClass="popupHover"143 PopupPosition="Right"144 runat="server">145 </cc1:HoverMenuExtender>146 <asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu">147 <div style="border:1px outset white">148 <div>149 <asp:LinkButton150 ID="lbtnInsertUpdate"151 runat="server"152 CausesValidation="True"153 CommandName="Insert"154 Text="Insert"155 OnClick="lbtnInsertUpdate_Click"156 />157 </div>158 <div>159 <asp:LinkButton160 ID="LinkButton2"161 runat="server"162 CausesValidation="False"163 CommandName="Cancel"164 Text="Cancel" /></div>165 </div>166 </asp:Panel>167 </EditItemTemplate>168 </asp:TemplateField>169 </Columns>170 </asp:GridView>171 </ContentTemplate>172 </asp:UpdatePanel>173 <asp:SqlDataSource174 ID="GetTeamDetailFormView"175 runat="server"176 ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX%>"177 SelectCommand="sp_GetTeamDetails"178 SelectCommandType="StoredProcedure"179 InsertCommand="sp_InsertDataInfo"180 InsertCommandType="StoredProcedure">181 <SelectParameters>182 <asp:Parameter Name="MarketID" />183 <asp:ControlParameter184 ControlID="ddlVPInfo"185 DefaultValue=""186 Name="vpid"187 PropertyName="SelectedValue"188 Type="Int32" />189 </SelectParameters>190 <InsertParameters>191 <asp:Parameter Name="TeamID" />192 <asp:Parameter Name="HeadCount" />193 <asp:Parameter Name="Orders" />194 <asp:Parameter Name="Revenue" />195 <asp:ControlParameter196 ControlID="tbEntryDat"197 Name="DataDate"198 PropertyName="Text"199 Type="String" />200 </InsertParameters>201 </asp:SqlDataSource>202 <hr />203 </ItemTemplate>204 </asp:TemplateField>205 </Columns>206 </asp:GridView>207208 <asp:SqlDataSource209 ID="SqlDataSource1"210 runat="server"211 ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX%>"212 SelectCommand="sp_GetMarketCats"213 SelectCommandType="StoredProcedure">214 <SelectParameters>215 <asp:ControlParameter216 ControlID="ddlVPInfo"217 DefaultValue=""218 Name="vpid"219 PropertyName="SelectedValue"220 Type="Int32" />221 </SelectParameters>222 </asp:SqlDataSource>223224 </ContentTemplate>225 <Triggers>226 <asp:AsyncPostBackTrigger227 ControlID="btnDisplayEntry"228 EventName="Click" />229 </Triggers>230 </asp:UpdatePanel>

The Code Behind

1Protected Sub lbtnInsertUpdate_Click(ByVal senderAs Object,ByVal eAs EventArgs)2Dim TeamInfoDBConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("XXXXXXXXXXXXXXXXX").ConnectionString)3Dim sqlStringAs String ="sp_InsertDataInfo"4Dim sqlCmdAs New SqlCommand(sqlString, TeamInfoDBConn)5 sqlCmd.CommandType = CommandType.StoredProcedure67'Dim NewText As String =8 'Dim val1 As TextBox = CType(e.Item.FindControl("TextBox3"), TextBox)9 'MsgBox(val1.Text)101112 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.TeamID", TextBox00.Text)13 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.HeadCount", TextBox1.Text)14 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.Orders", TextBox2.Text)15 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.Revenue", TextBox3.Text)16 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.DataDate", tbEntryDate.Text)1718 TeamInfoDBConn.Open()19 sqlCmd.ExecuteNonQuery()20 TeamInfoDBConn.Close()21 sqlCmd =Nothing22 End Sub

Bump...Still looking for anyone that might have some idea about this one?? thank-you!

Saturday, March 24, 2012

Listview passing parameters problem

I use Listview by declaretive method and bind a method of webservice to it.But i want to pass parameters to its select method so i could select data with some restriction values.How can i do this?

<components>

<dataSource id="dataSourceMV" serviceURL="MainPageWebService.asmx"autoLoad="true" loadMethod="SelectMostValuableList" />...

Thanks

Hi,

first of all I have a question: really is your service method being called, even without parameters? (see the end of my post).

The DataSource control exposes aparameters object that you can use to pass parameters to your method. To do this, you have to expand the parameters object by adding a property with theexact name of the parameter, as declared in your method signature.

For example, suppose that I want to set the myparam parameter with the value of a textbox:

<dataSource id="dataSourceMV"
serviceURL="MainPageWebService.asmx"
serviceType="Handler"
autoLoad="true"
loadMethod="SelectMostValuableList"
>
<bindings>
<binding dataContext="myTextBox"
dataPath="text"
property="parameters"
propertyKey="myparam"
direction="In"
/>
</binding>
</bindings>
</dataSource>

Notice that you have to set theserviceType attribute to "Handler" if you want to be able to call a service method, otherwise you have to use a DataService.

Ok, now the bad news: probably this example will not work at all, because there's a bug in the March CTP that makes impossible to call service methods from a DataSource control, so you'll have to use a DataService (or declare a method calledGetData in your web service, that returns structured data).


Hi,

just a precisation on my previous post (I'm unable to edit it, maybe due to a forum upgrade?): using the March CTP is not possible to call, from a DataSource control, service methods defined in classic web services (i.e. classes that inherit from the System.Web.Services.WebService class), but it is possible to call methods defined in a class that inherits from the DataService class.


I dont understand how to use in webservice code ,in below code i want to access (send) parameter1.What do i have to exactly write in listview's datasource

<components>
<dataSource id="dataSource" serviceURL="MainPageWebService.asmx" autoLoad="true" loadMethod="SelectMostValuableList" />
<listView id="dataContents" itemTemplateParentElementId="masterTemplate" propertyChanged="onChange" >
<bindings>
<binding dataContext="dataSource" dataPath="data"property="data" ></binding>
</bindings>
<layoutTemplate>
<template layoutElement="masterTemplate"/>
</layoutTemplate>
<itemTemplate>
<template layoutElement="masterItemTemplate">
<label id="masterName">
<bindings>
<binding dataPath="miktar" property="text"/>
</bindings>
</label>
</template>
</itemTemplate>
</listView>
</components>

[DataObjectMethod(DataObjectMethodType.Select)]
public BLL.Collections.EnDegerlilerAtlas[] SelectMostValuableList(string myParameter1)
{
return MainPageWebService.Data7.ToArray();
}
Hi,

where does the myParameter1 value come from? Is it a form parameter, a bound value? Knowing this I can show you the appropriate code.
i want to pass just form parameter value like <input id="Hidden1" type="hidden" value="myParameter1" /> myParameter1 value to dataService.

Hi,

since we want to set parameters declaratively, we should upgrade the hidden field to an Atlas control, but no wrapper for the hidden field is provided by the framework. At this point, you could try to use a <textBox /> control:

<textBox id="myHiddenField" />

and then declare the DataSource control in this way:

<dataSource id="dataSource"
serviceURL="MainPageWebService.asmx"
loadMethod="SelectMostValuableList"
autoLoad="true"
>

<bindings>
<binding dataContext="myHiddenField"
dataPath="text"
property="parameters"
propertyKey="myParameter1"
direction="In"
/>
</bindings>

</dataSource>

In the declaration above, the value of the hidden field is bound to the value of myParameter1.


Hi All and Garbin,

When i execute the code that Garbin has provided, I get an error:

Assertion Failed: Could not resolve reference to object named "ctl00_ContentPlaceBody_HiddenLabel" for "dataContext" property on object of type "Sys.Binding"

and my page doesn't work.

Declaration of this Label is:

<

asp:LabelID="HiddenLabel"runat="server"></asp:Label>

Xml Script:

<components>
<dataSource id = "dataSource"
serviceURL = "EventsWebService.asmx"
autoLoad = "true"
loadMethod = "GetGeneralEvents"
>
<bindings>
<binding dataContext = "ctl00_ContentPlaceBody_HiddenLabel"
dataPath = "text"
property = "parameters"
propertyKey = "ClientLogin"
direction = "In"
/>
</bindings>

The --> dataContext = "ctl00_ContentPlaceBody_HiddenLabel" <--

portion is hard coded as currently i don't know how to pass the generated control id to the XML Script.

Urgent help is HIGHLY appriciated. :)


Ok, I failed to understand "upgrade your hidden field to an Atlas Control"

so now code lOOks like this:

<

labelid="HiddenLabel"><%=CurrentClient.Login%></label>

<dataSource id = "dataSource"
serviceURL = "EventsWebService.asmx"
autoLoad = "true"
loadMethod = "GetGeneralEvents"
>
<bindings>
<binding dataContext = "HiddenLabel"
dataPath = "text"
property = "parameters"
propertyKey = "ClientLogin"
direction = "In"
/>
</bindings>
</dataSource>
.

.

.

<label id="HiddenLabel">
<bindings>
<binding property="text" dataPath="text" />
</bindings>
</label>

:( but still i have an error saying :

No data context available for binding with ID "" and dataPath "text" on object of type "Sys.UI.Label"


Hi,

ok, let's start with the last snippet you posted. The <binding /> inside the dataSource control has dataContext="HiddenLabel". This means that there must be an Atlas control with the id of "HiddenLabel". This control is declared below, but encapsulates a binding that isn't needed. Try to remove it:

<label id="HiddenLabel" />
Hi,

Sentimotive:


I failed to understand "upgrade your hidden field to an Atlas Control"


when I say "upgrading something to an Atlas control", I mean associate to a portion of static HTML (one element or a whole set of elements) an Atlas control.

For example, if you declared a textbox like

<input type="text" id="myTextBox" />
you can upgrade it to an Atlas TextBox by adding a control in the xml-script section:

<textBox id="myTextBox" />

Now, myTextBox is also an Atlas control (before, it was only a DOM element), and the element is encapsulated inside the control.
Regarding the hidden field, there isn't a specific Atlas control that wraps it. What you could do in this case is upgrade the hidden field to a TextBox and use the text property to get the hidden field's value:

<input type="hidden" id="myHiddenField" />
<textBox id="myHiddenField" />

But the above code is a sort of hack, and the best approach would be to write a specific Atlas control that wraps the hidden field element.
Hi,

btw, coding a little Atlas control that wraps an hidden field element is not difficult:

Type.registerNamespace('AtlasUI.HiddenField');

AtlasUI.HiddenField = function(associatedElement) {
AtlasUI.HiddenField.initializeBase(this, [associatedElement]);

// get/set the value.
this.get_value = function() {
return this.element.value;
}
this.set_value = function(val) {
if(val != this.element.value) {
this.element.value = val;
}
}

// Allow declarative programming against this control.
this.getDescriptor = function() {
var td = AtlasUI.HiddenField.callBaseMethod(this, 'getDescriptor');

td.addProperty('value', String);

return td;
}
}
AtlasUI.HiddenField.registerClass('AtlasUI.HiddenField', Sys.UI.Control);
Sys.TypeDescriptor.addType('script', 'hiddenField', AtlasUI.HiddenField);