11 Replies - 416 Views - Last Post: 14 February 2019 - 10:18 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,933
  • Joined: 12-January 10

get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 06:41 AM

hello all,

it has been years since i've had to do something that was telerik so i'm stuck on a little item. How do i get the value from a hidden field that is read only?

<asp:TemplateField HeaderText="WebPortalID" SortExpression="WebPortalID"  Visible="false" >
                <ItemTemplate>
                    <asp:Label ID="WebPortalID" runat="server" readonly="true" Text='<%# Bind("WebPortalID") %>'></asp:Label>
                </ItemTemplate>




ive tried all of these:

        Dim portalID As Label = grdAddPortals.FindControl("WebPortalID")
        Dim pid As Integer = grdAddPortals.ItemType.f blah blah



        'CType(grdAddPortals.FindControl("WebPortalID"), Label)

        ' FindControl("WebPortalID")

        ' DataKeys[e.RowIndex].Value.ToString()




thoughts?

Is This A Good Question/Topic? 0
  • +

Replies To: get value from hidden and read only field asp.net vb.net back end

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6777
  • View blog
  • Posts: 27,959
  • Joined: 12-December 12

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 07:15 AM

I know nothing about ASP.NET, olde stylie, but...

Dim portalID As Label = grdAddPortals.FindControl("WebPortalID")

Doesn't this work? What error does it give you?

Once you have the control reference, I guess you'd be looking for .Text, not a Value, as it is a Label.



That label doesn't repeat in the grid does it? If so, then it shouldn't reuse the same id and you would have to find a way to get the first version of the label... but I am speculating hugely about this ;)
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,933
  • Joined: 12-January 10

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 07:31 AM

it returns "Label:Nothing"--- i even tried that with a label i know has wording in it

i hear yeah -- i havent had to use this since 2014-- been all telerik since then
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6777
  • View blog
  • Posts: 27,959
  • Joined: 12-December 12

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 07:42 AM

What returns "Label:Nothing"? Do you mean the attempt to read .Text? If that is the case then does that mean that you have successfully obtained a reference to the label? If so, then look through the intellisense of portalID for something sexy.
Was This Post Helpful? 0
  • +
  • -

#5 TechnoBear   User is offline

  • Lady A
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,249
  • Joined: 02-November 11

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 08:01 AM

WebPortalID.Text

maybe
WebPortalID.Value


Thank you for coming to my TED talk.

---------------

In all seriousness, the runat='server' registers it as a server side control, so you can access it from the server side using it's ID value.

I would probably make the label ID lbl[Label Name] to differentiate it from variables on the server side but that's just me and I've only been doing this for like 10 years.

This post has been edited by TechnoBear: 14 February 2019 - 08:03 AM

Was This Post Helpful? 0
  • +
  • -

#6 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,933
  • Joined: 12-January 10

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 08:11 AM

View Postandrewsw, on 14 February 2019 - 09:15 AM, said:

I know nothing about ASP.NET, olde stylie, but...

Dim portalID As Label = grdAddPortals.FindControl("WebPortalID")

Doesn't this work? What error does it give you?

Once you have the control reference, I guess you'd be looking for .Text, not a Value, as it is a Label.



That label doesn't repeat in the grid does it? If so, then it shouldn't reuse the same id and you would have to find a way to get the first version of the label... but I am speculating hugely about this ;)/>



this line Dim portalID As Label = grdAddPortals.FindControl("WebPortalID")




on debug it returns the label:nothing
Was This Post Helpful? 0
  • +
  • -

#7 TechnoBear   User is offline

  • Lady A
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,249
  • Joined: 02-November 11

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 08:15 AM

View Postandrewsw, on 14 February 2019 - 08:15 AM, said:

That label doesn't repeat in the grid does it? If so, then it shouldn't reuse the same id and you would have to find a way to get the first version of the label... but I am speculating hugely about this ;)/>


Mate check out my answer, but this is a factor I overlooked. I didn't see a grid in the presented question so I didn't factor for something like that, but if it is a repeating child control, you need to get the parent grid, find the right row, then pull the control and get it's value.

What exactly is the scenario here? Where is this label? Is it a grid column?
Was This Post Helpful? 0
  • +
  • -

#8 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,933
  • Joined: 12-January 10

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 08:29 AM

 <asp:GridView runat="server" id="grdAddPortals" AllowPaging="True" PageSize="20" AllowSorting="true" AutoGenerateColumns="False" Width="100%" CellSpacing="0" CellPadding="0" CssClass="DataGridRow"   ShowFooter="true" DataKeyNames="WebPortalID" OnRowEditing="grdAddPortals_RowEditing" OnRowCancelingEdit="grdAddPortals_RowCancelingEdit" OnRowDeleting="grdAddPortals_RowDeleting" OnRowUpdating="grdAddPortals_RowUpdating" onrowdatabound="grdAddPortals_RowDataBound"   >
            <HeaderStyle  CssClass="DataGridHeader" />
            <AlternatingRowStyle CssClass="DataGridAlternateRow" />
            <EditRowStyle  CssClass="DataGridRow" />
            <Columns>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:LinkButton  id="editBtn" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                     </ItemTemplate>
                      <FooterTemplate>
                             <asp:Button ID="AddBtn" runat="server" Text="Add New Row" CommandName="Insert" />
                        </FooterTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:LinkButton  id="deleteBtn" runat="server" CommandName="Delete"   >Delete</asp:LinkButton>
                     </ItemTemplate>
                 </asp:TemplateField>          
               <asp:TemplateField HeaderText="WebPortalID" SortExpression="WebPortalID"  Visible="false" >
                <ItemTemplate>
                    <asp:Label ID="WebPortalID" runat="server" readonly="true" Text='<%# Bind("WebPortalID") %>'></asp:Label>
                </ItemTemplate>
                </asp:TemplateField>



what i am trying to do is hit the delete button and it should grab the webportal id that is on every row and run sql to delete the item

Attached image(s)

  • Attached Image

This post has been edited by DarenR: 14 February 2019 - 08:30 AM

Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6777
  • View blog
  • Posts: 27,959
  • Joined: 12-December 12

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 08:36 AM

If it (the column) is not visible anyway, then wouldn't an input/textbox be better - more natural - than a label?

But I'll drop out as I don't do ASP.NET ;)
Was This Post Helpful? 0
  • +
  • -

#10 TechnoBear   User is offline

  • Lady A
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,249
  • Joined: 02-November 11

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 09:33 AM

What I would do is have a function that uses deleteBtn.Click as the Handle and using the row number run the following:

Dim PortalID as String = grdAddPortals.Rows(RowNumber).WebPortalID.Text
//Code to Delete per WebPortalID

Seems like the simplest solution. I am currently working in C# so I don't have a way to verify the actual property for grdAddPortals.Rows but it'll be something like that.
Was This Post Helpful? 0
  • +
  • -

#11 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,933
  • Joined: 12-January 10

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 09:59 AM

finally figured it out after a ton of tries:

Protected Sub grdAddPortals_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
        Dim portalID As Integer = Convert.ToInt32(grdAddPortals.DataKeys(e.RowIndex).Value)

        '//delete the portal
        deleteRecord(portalID)
        grdAddPortals.EditIndex = -1
        BindGrid()


    End Sub


View PostTechnoBear, on 14 February 2019 - 11:33 AM, said:

What I would do is have a function that uses deleteBtn.Click as the Handle and using the row number run the following:

Dim PortalID as String = grdAddPortals.Rows(RowNumber).WebPortalID.Text
//Code to Delete per WebPortalID

Seems like the simplest solution. I am currently working in C# so I don't have a way to verify the actual property for grdAddPortals.Rows but it'll be something like that.



yeah i just started a new job and they are old school vb.net and asp.net


im coming from c# and telerik
Was This Post Helpful? 0
  • +
  • -

#12 TechnoBear   User is offline

  • Lady A
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,249
  • Joined: 02-November 11

Re: get value from hidden and read only field asp.net vb.net back end

Posted 14 February 2019 - 10:18 AM

Don't knock it, 90% of my career has been VB.Net.

I am glad you got it figured out :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1