monachan
asked on
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="confirmSub mit()" 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.
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="confirmSub
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>
ASKER
can pls explain this with code details.
i am unable to follow the first 2 points.
thanks you
i am unable to follow the first 2 points.
thanks you
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.
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.
ASKER
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("b tnViewDeta ils");
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="BlueMagentaButtonS kinSmall2" 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="BlueMagentaButtonS kinSmall2" runat="server"
Text='<%#Eval("emailaddres s")%>' OnClick="btnSelect_Click" />
</ItemTemplate>
</asp:TemplateField>
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("b
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="BlueMagentaButtonS
Text="Delete" OnClientClick="return confirmSubmit()" OnClick="btnConfirmDelete_
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ControlStyle-Width="150px"
<ItemTemplate>
<asp:LinkButton ID="btnViewDetails" SkinID="BlueMagentaButtonS
Text='<%#Eval("emailaddres
</ItemTemplate>
</asp:TemplateField>
document.getElementById("b tnViewDeta ils"); 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 & """)%>'
/>
ASKER
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
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
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.
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.
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_R owDeleting " OnRowDataBound="GridView1_ RowDataBou nd">
Then in the code-behind,
protected void GridView1_RowDeleting(obje ct Sender, GridViewDeleteEventArgs e)
{
//code to delete row
}
protected void GridView1_RowDataBound(obj ect Sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
((LinkButton)e.Row.FindCon trol("lbde lete")).On ClientClic k = "return confirm('Are you sure you want to delete " + PUT_EMAILID_HERE + "?');";
}
}
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_R
Then in the code-behind,
protected void GridView1_RowDeleting(obje
{
//code to delete row
}
protected void GridView1_RowDataBound(obj
{
if (e.Row.RowType == DataControlRowType.DataRow
{
((LinkButton)e.Row.FindCon
}
}
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() & """)%>'
/>
ASKER
hi.,
the code compiles.but keep on throwing runtime error.......
failed to load the popup also.
in this code
protected void GridView1_RowDataBound(obj ect Sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
((LinkButton)e.Row.FindCon trol("lbde lete")).On ClientClic k = "return confirm('Are you sure you want to delete " + PUT_EMAILID_HERE + "?');";
}
}
i cannot comlie because 'emailaddress' is not existing in the current context.
the code compiles.but keep on throwing runtime error.......
failed to load the popup also.
in this code
protected void GridView1_RowDataBound(obj
{
if (e.Row.RowType == DataControlRowType.DataRow
{
((LinkButton)e.Row.FindCon
}
}
i cannot comlie because 'emailaddress' is not existing in the current context.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for who gave the input .i was able to get it done,
this code worked.
((LinkButton)e.Row.FindCon trol("Link Button1")) .OnClientC lick = "return confirm('Are you sure you wish to delete the LocalAddress " + ((LinkButton)e.Row.FindCon trol("btnV iewDetails ")).Text + "?');";
this code worked.
((LinkButton)e.Row.FindCon
ASKER
thank you guys
colonel720: & davrob60:
thankyou very much
colonel720: & davrob60:
thankyou very much
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help.
Why did we get a "B"
https://www.experts-exchange.com/help.jsp#hi403
"an answer is worth an A, unless it doesn't resolve your issue"
ASKER
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.
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.
it`s at the top of the page, just unter the question Code Snippet text and before the "view solution" button.
Thanks!
Thanks!
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="btnConfirmDeleteDetail
Text="Delete" OnClientClick='<%# "confirmSubmit(""" & EMailAddress.clientid & """)%>'
/>
3 add a parameter to your jascript function tu retrive the control :
function OnClientClick(EMailAddress
var EMailAddressIDObject = document.getElementById(EM
...