C#.net--Ajax-- how do i get the value of a bound filed which is inside an update panel ---from a javscript fuction call.

i am having an AJax update panel control in which a gridview is placed.when the form loaded the gridview is binded with values from database.

the first column of the grid view is a <asp:LinkButton for delete.

other columns are  <asp:BoundField with values such as EMailAddress,GroupId etc.

when user click on 'delete' link a java script popup should come for delete confirmation.

i have added a 'OnClientClick="confirmSubmit()"  in the <asp:LinkButton which brings the javascript popup.........cool!!!!!!!!!

now the problem is i need to get the EMailId from the form  inside the JavaScript function so that i can say

"are sure you want to delete this" + EmailId

but i don't know how can i get the value of the EId from form .
pls give me some leads.
<asp:UpdatePanel ID="updPnlDisplayLocalAddresses" runat="server" UpdateMode="Conditional">
                                                            <ContentTemplate>
                                                                <asp:GridView ID="gvLocalAddresses" runat="server" Width="403px" AutoGenerateColumns="False"
 
                                                                            <asp:TemplateField ControlStyle-Width="150px" HeaderStyle-Width="60px" HeaderText="Address">
 
                                                                            <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" HeaderText="">
                                                                                <ItemTemplate>
                                                                                    <asp:LinkButton ID="btnConfirmDeleteDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
                                                                                        Text="Delete"  OnClientClick="confirmSubmit()" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
 
                                                                                <ItemTemplate>
                                                                                    <asp:LinkButton ID="btnViewDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
                                                                                        Text='<%#Eval("emailaddress")%>' OnClick="btnSelect_Click" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
                                                                       
 
                                                                            <asp:BoundField HeaderText="Group Id" DataField="groupid" ItemStyle-HorizontalAlign="left"  />
                                                       </asp:UpdatePanel>
 
 
<script language="javascript" type="text/javascript">
     function confirmSubmit()
     {
 
''need to get the EMailAddress from fom here . 
      var agree=confirm("Are you sure you wish to delete this LocalAddress "+EMail Address from form...);
 
      if (agree)
 
       return true ;
 
      else
 
       return false ;
   }
</script>

Open in new window

monachanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David RobitailleAnalyst ProgrammerCommented:
here how i did it in a previous project.
1 replace your BoundField with template field that have id
2 link the function in the LinkButton  using the new feilds is client id (in my case, i use
onfocus instead of onclient click):

<asp:LinkButton ID="btnConfirmDeleteDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
                                                                                        Text="Delete"  OnClientClick='<%# "confirmSubmit(""" & EMailAddress.clientid & """)%>'
/>
3 add a parameter to your jascript function tu retrive the control :

function OnClientClick(EMailAddressID){
var EMailAddressIDObject = document.getElementById(EMailAddressID);
...

 

 
0
monachanAuthor Commented:
can pls explain this with code details.

i am unable to follow the first 2 points.

thanks you
0
David RobitailleAnalyst ProgrammerCommented:
the point 1 is about replacing the BoundField with Templatefield using labels and textbox. that way, those will have "controlID" that will be retrievable from asp.net.
the point 2 is about filling the parameter of the onclientclick function with a string. that string is build using the clientid (the name of the control on the client side)  of the new controls created in 1. Since the controls are within a GridView, they will have different names from a row to an other. That way the java script will receive the name of the control to find as a string.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

monachanAuthor Commented:
sir,

infact this is the code i am using to display a delete link in the first column & the EmailId as a link in the second column.i think i should get the value in javascript using
      var myTextField = document.getElementById("btnViewDetails");

but i am not .can pls look into this code.


                                                                            <asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" HeaderText="">
                                                                                <ItemTemplate>
                                                                                    <asp:LinkButton ID="btnConfirmDelete" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
                                                                                        Text="Delete"  OnClientClick="return confirmSubmit()" OnClick="btnConfirmDelete_Click" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>


                     <asp:TemplateField ControlStyle-Width="150px" HeaderStyle-Width="60px" HeaderText="Address">
                                                                                <ItemTemplate>
                                                                                    <asp:LinkButton ID="btnViewDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
                                                                                        Text='<%#Eval("emailaddress")%>' OnClick="btnSelect_Click" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>


0
David RobitailleAnalyst ProgrammerCommented:
document.getElementById("btnViewDetails"); wont work because the id of the btnViewDetails will change form a row to an other (check the source). that why you shoul retrive it using clientID.
 

<asp:LinkButton ID="btnConfirmDeleteDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
             Text="Delete"  OnClientClick='<%# "confirmSubmit(""" & btnViewDetails.clientid & """)%>' 
/>

Open in new window

0
monachanAuthor Commented:
thanks for the code sample.looks like am clos to the sloution.


when  i try to use this line of code for the link button i am not able to complile .a wierd error 'NewLine in constant' is dilplayed.

i tryed different things adding and removing.the compile erroe occurs only whein i add the code

'<%# "confirmSubmit(""" & btnViewDetails.clientid & """)%>'  in the Linl.

if i pass a simple valued that is bening acceptd by Javascript

pls see/help
0
David RobitailleAnalyst ProgrammerCommented:
i dont know...i dont remember saw this...
but i just googled it and i found this.
http://support.microsoft.com/kb/827420
also check on experts-excange. i saw other question with this error.
0
David RobitailleAnalyst ProgrammerCommented:
0
colonel720Commented:
You could do this:

Have a template column for the delete link:
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lbdelete" runat="server" Text="Delete" CommandName="Delete" />
                    </ItemTemplate>
                </asp:TemplateField>

then put the following event handlers on the grid declaration:

<asp:GridView ID="GridView1" runat="server" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound">

Then in the code-behind,

protected void GridView1_RowDeleting(object Sender, GridViewDeleteEventArgs e)
        {
            //code to delete row
        }
        protected void GridView1_RowDataBound(object Sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((LinkButton)e.Row.FindControl("lbdelete")).OnClientClick = "return confirm('Are you sure you want to delete " + PUT_EMAILID_HERE + "?');";
            }
        }
0
David RobitailleAnalyst ProgrammerCommented:
i just think of it and, instead of passing the id (btnViewDetails.clientid ), you could pass the binded value direcly Eval("emailaddress")
 

<asp:LinkButton ID="btnConfirmDeleteDetails" SkinID="BlueMagentaButtonSkinSmall2" runat="server"
             Text="Delete"  OnClientClick='<%# "confirmSubmit(""" & Eval("emailaddress").tostring() & """)%>' 
/>

Open in new window

0
monachanAuthor Commented:
hi.,


the code compiles.but keep on throwing runtime error.......
failed to load the popup also.

in this code

protected void GridView1_RowDataBound(object Sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((LinkButton)e.Row.FindControl("lbdelete")).OnClientClick = "return confirm('Are you sure you want to delete " + PUT_EMAILID_HERE + "?');";
            }
        }

i cannot comlie because 'emailaddress' is not existing in the current context.


0
colonel720Commented:
you would need to get the email address from the row:
replace PUT_EMAILID_HERE with e.Row.Cells[emailColumnIndex].Text
or if you have a named template column for the email field: ((ITextControl)e.Row.FindControl("lblEmail")).Text
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
monachanAuthor Commented:
thanks for who gave the input .i was able to get it done,
this code worked.

                        ((LinkButton)e.Row.FindControl("LinkButton1")).OnClientClick = "return confirm('Are you sure you wish to delete the LocalAddress " + ((LinkButton)e.Row.FindControl("btnViewDetails")).Text + "?');";
0
monachanAuthor Commented:
thank you guys

colonel720:  &  davrob60:

thankyou very much

0
David RobitailleAnalyst ProgrammerCommented:
You are welcome!
 Just accept multiple solution to split the point between colonel720 and me.
0
colonel720Commented:
Glad to help.
0
David RobitailleAnalyst ProgrammerCommented:

Why did we get a "B"
http://www.experts-exchange.com/help.jsp#hi403 
"an answer is worth an A, unless it doesn't resolve your issue"
0
monachanAuthor Commented:
sir,

infact i never  completely read the pointing system.so i was not aware about this;i am glad to give 'A' because it was a difficult qn.
but how do i change the grade........

the document says

'If you feel you have graded a solution incorrectly, click the Request Attention button and the Moderators will change it for you.'
i don't see any 'Request Attension' button.
0
David RobitailleAnalyst ProgrammerCommented:
it`s at the top of the page, just unter the question Code Snippet text and before the "view solution" button.
Thanks!
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.