I have the code as below ,
For ASPX-->
<telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicking="onClientContextMenuItemClicking"
OnItemClick="RadContextMenu1_ItemClick" OnInit="RadContextMenu1_OnInit">
<Items>
<telerik:RadMenuItem Value="AddNick" Text="" />
<telerik:RadMenuItem Value="Edit" Text="" />
<telerik:RadMenuItem Value="Delete" Text="" Font-Bold="true" />
</Items>
</telerik:RadContextMenu>
Javascript -->
var allowPosback = false;
function confirmCallBackFn(arg, eventArgs) {
if (arg) {
allowPosback = true;
}
}
function onClientContextMenuItemClicking(sender, eventArgs) {
var item = eventArgs.get_item();
item.get_menu().hide();
switch (item.get_value()) {
case "Delete":
var message = "Delete"
var event = "event";
var width = 300;
var height = 100;
var title = "Want To Delete";
radconfirm(message, confirmCallBackFn, width, height, null, title);
eventArgs.set_cancel(allowPosback);
break;
}
}
control is RadContextMenu not postback after confirm clicking why it is not having post back. Any help would be great ?
I think you've misunderstood how the radconfirm box works. I've recently answered a similar question (Strange behavior of confirmation in Telrik ?) which should help you re-write the code above to work properly.
Also you might find the following link useful (also posted at end of other answer): http://demos.telerik.com/aspnet-ajax/window/examples/confirmserverclicks/defaultcs.aspx.
Related
I tried this code on jQuery to change the btn text when I click on a span that opens a modal to add a ShipWay.
$(document).ready(function () {
$("#spanOpen").click(function () {
$("#fulldiv").fadeIn(1000);
$('#titleModal').text('הוספת שלוחה');
$("#ContentPlaceHolder1_btnAddShip").prop('value', 'הוסף');
$('#ContentPlaceHolder1_txtShipName').val('');
$('#ContentPlaceHolder1_txtShipPrice').val('');
$('#ContentPlaceHolder1_txtShipStart').val('');
$('#ContentPlaceHolder1_txtShipEnd').val('');
$('#ContentPlaceHolder1_txtShipPremium').val('No');
});
$(".close").click(function () {
$("#fulldiv").fadeOut(500);
});
});
function UpdateClick(btn)
{
$("#fulldiv").fadeIn(1000);
var row = btn.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
$('#ContentPlaceHolder1_txtShipName').val(row.cells[6].innerHTML);
$('#ContentPlaceHolder1_txtShipPrice').val(row.cells[5].innerHTML);
$('#ContentPlaceHolder1_txtShipStart').val(row.cells[4].innerHTML);
$('#ContentPlaceHolder1_txtShipEnd').val(row.cells[3].innerHTML);
$('#ContentPlaceHolder1_txtShipPremium').val(row.cells[2].innerHTML);
$('#titleModal').text('עדכן שלוחה');
$("#ContentPlaceHolder1_btnAddShip").prop('value', 'עדכן');
return false;
}
This is the button I use in my html for Add/Update the row:
<asp:Button ID="btnAddShip" runat="server" ValidationGroup="AddShip" Text=""
CssClass="btn" OnClick="btnAddShip_Click" />
When I tried to check his text in the code behind he said that he have nothing like = "".
This is my code in the C#
In the first if I want to ask if the text of the button is Add
and if not it will be Update in the else
the code go for WebService and to Xml
I tried the code he works well I just need that if will work perfect
because I don't want to create another button
ElectricWSL.Ship ship = new ElectricWSL.Ship();
ship.ShipName = txtShipName.Text.Trim();
ship.ShipPremium = txtShipPremium.Text.Trim();
ship.ShipPrice = double.Parse(txtShipPrice.Text);
ship.ShipStartTime = txtShipStart.Text.Trim();
ship.ShipEndTime = txtShipEnd.Text.Trim();
if (btnAddShip.Text == "הוסף")
{
ws.WSLAddShip(ship);
ShowXMLGrid();
}
else
{
int rowIndex = GetRow(txtShipName.Text);
ws.WSLUpdateShip(ship, rowIndex);
ShowXMLGrid();
}
Answering one of your point in details when i tried to check his text in the code behind it contains like =""
Button text is empty in code because
<asp:Button ID="btnAddShip" runat="server" ValidationGroup="AddShip" Text=""
CssClass="btn" OnClick="btnAddShip_Click" />
Add some text to it like
<asp:Button ID="btnAddShip" runat="server" ValidationGroup="AddShip" Text="Add"
CssClass="btn" OnClick="btnAddShip_Click" />
And get it in code behind like
if (btnAddShip.Text == "Add")
{
ws.WSLAddShip(ship);
ShowXMLGrid();
}
else
{
int rowIndex = GetRow(txtShipName.Text);
ws.WSLUpdateShip(ship, rowIndex);
ShowXMLGrid();
}
There is a radgrid with one of the column as checkbox in
itemtemplate.
I want to loop through this radgrid's items. And based on each item's checkbox.checked condition, enable a seperate button control.(in client-side using javascript)
I've deviced code for this, but it is not giving the desired output.
What's wrong in this please.
Javascript:
<telerik:RadScriptBlock ID="scriptBlock1" runat="server">
<script type="text/javascript">
function checkRestrictionAcceptance()
{
var masterTable = $find("<%=RGGroupedCartRestrictedAssets.ClientID%>").get_masterTableView();
var count = masterTable.get_dataItems().length;
var checkbox;
var item;
for (var i = 0; i < count; i++)
{
item = masterTable.get_dataItems()[i];
checkbox = item.findElement("AcceptedCheckbox");
alert(checkbox.checked);
if (checkbox.checked)
{
var DownloadButton = document.getElementById('DownloadButton');
DownloadButton.enabled = false;
}
}
}
</script>
</telerik:RadScriptBlock>
Aspx:
<telerik:RadGrid ID="RGGroupedCartRestrictedAssets" runat="server" DataSourceID="CslaDSGroupedCartRestrictedAssets" AutoGenerateColumns="False"
GridLines="None" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" EnableEmbeddedSkins="false">
<MasterTableView DataSourceID="CslaDSGroupedCartRestrictedAssets" DataKeyNames="RestrictionText">
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Checkbox ID="AcceptedCheckbox" runat="server" />
</ItemTemplate>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:Button ID="DownloadButton" runat="server" Text = "Test" OnClientClick ="checkRestrictionAcceptance();"/>
You need to specify the clientID of the DownloadButton
var DownloadButton = document.getElementById('<%=DownloadButton.ClientID%>');
I'm not sure which browser you're using, but I think that using the 'i' directly in get_dataItems() can be problematic with Firefox. Your code worked fine for me in IE10 using Telerik.Web.UI 2013.3.1324.45 - I am getting the value of checkbox.checked. Try this instead though, it might help:
function checkRestrictionAcceptance() {
var masterTable = $find("<%=RGGroupedCartRestrictedAssets.ClientID%>").get_masterTableView();
var count = masterTable.get_dataItems().length;
var checkbox;
var items = masterTable.get_dataItems();
for (var i = 0; i < count; i++) {
checkbox = items[i].findElement("AcceptedCheckbox");
alert(checkbox.checked);
if (checkbox.checked) {
var downloadButton = document.getElementById('<%=DownloadButton.ClientID%>');
downloadButton.enabled = false;
}
}
I'm roughly following the concept from this link. To simulate a nested GridView.
It looks like this:
Basically I'm creating a second row which is display:none and want to toggle it using JavaScript.
JavaScript and aspx code:
<script type="text/javascript" language="JavaScript">
function detailsToggle(Company_ID) {
try {
detail_row = document.getElementById('detailsRow_' + Company_ID);
parent_row = document.getElementById('parentRow_' + Company_ID);
img = parent_row.cells[0].firstChild;
if (detail_row.className !== 'hidden') {
detail_row.className = detail_row.className + ' hidden';
img.src = '../Images/icons/+.gif';
}
else {
detail_row.className = detail_row.className.replace(/\bhidden\b/, '');
img.src = '../Images/icons/-.gif';
}
}
catch(ex) { alert(ex); }
}
</script>
<style type="text/css">
.hidden
{
display: none;
}
</style>
<asp:GridView ID="gvLegalEntityBrowser" DataKeyNames="Company_ID" AutoGenerateColumns="False"
runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
OnRowDataBound="gvLegalEntityBrowser_RowDataBound" OnPageIndexChanging="pagingIndexChanged"
AllowPaging="True" PageSize="25" AllowSorting="false">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%--Placeholder --%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CompanyCode" HeaderText="CompanyCode" SortExpression="CompanyCode" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
</Columns>
<EmptyDataTemplate>No data</EmptyDataTemplate>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
... and my apsx.cs RowDataBound Method:
//Idea from : http://www.codeproject.com/Articles/160773/Expandable-Rows-in-GridView
protected void gvLegalEntityBrowser_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvRow = e.Row as GridViewRow;
Int64 iCompanyID = 0; //Get Company_ID for Legal Entity Row
iCompanyID = System.Convert.ToInt64(gvLegalEntityBrowser.DataKeys[gvRow.RowIndex]["Company_ID"]);
GridView gvLegalEntityRelation = new GridView();
gvRow.ID = "parentRow_" + iCompanyID;
gvRow.ClientIDMode = ClientIDMode.Static; //Set HTML ID element = control.ID
//Add javascript toggle button to each row
System.Web.UI.WebControls.ImageButton toggleButton = new System.Web.UI.WebControls.ImageButton();
toggleButton.ID = "btnToggle_" + iCompanyID;
toggleButton.ImageUrl = "../Images/icons/+.gif";
toggleButton.OnClientClick = "detailsToggle(" + (iCompanyID) + ")";
gvRow.Cells[0].Controls.Add(toggleButton);
toggleButton.Attributes.Add("onmouseover","this.style.cursor='hand'");
toggleButton.Attributes.Add("onmouseout", "this.style.cursor='default'");
using (dsLegalEntitiesTableAdapters.View_LegalEntityRelationCountTableAdapter daLERelCount = new dsLegalEntitiesTableAdapters.View_LegalEntityRelationCountTableAdapter())
{
//Set Details Data Source
gvLegalEntityRelation.DataSource = daLERelCount.GetRelationsDataByCompanyID(iCompanyID);
gvLegalEntityRelation.AutoGenerateColumns = true;
GridViewRow detailsgvRow = new GridViewRow(gvRow.RowIndex + 1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
detailsgvRow.CssClass = "hidden";
detailsgvRow.ID = "detailsRow_" + iCompanyID;
detailsgvRow.ClientIDMode = ClientIDMode.Static; //Set HTML ID element = control.ID
TableCell cell = new TableCell();
cell.ColumnSpan = 4;
cell.BorderStyle = BorderStyle.None;
cell.Controls.Add(gvLegalEntityRelation);
detailsgvRow.Cells.Add(cell);
((GridView)sender).Controls[0].Controls.Add(detailsgvRow);
gvLegalEntityRelation.DataBind();
}
}
}
The JavaScript works fine, and I even see the correct Result for a split second:
... but the the parent GridView rebuilds into something like this:
Q: Does anyone have an Idea what may be causing the GridView to rebuild??
So... the problem was actually quite basic. A colleague pointed this out to me.
I used an ImageButton to expand the inner table. The .NET image button has Click handler and ClientClick handler. Click tells what to do on PostBack, and ClientClick passes on to JavaScript.
Apparently, even if I don't define a target function for Click, the page still does a Post-Back. Thus first the javascript works, and then the page does a post-back, messing up the page.
Solution: exchange ImageButton for a simple image with click-event for javascript.
On my page, I have reportviewer.
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
CssClass="ReportViewer" AsyncRendering="false"
OnPreRender="RptViewer_PreRender" EnableViewState="true"
Width="100%" PageCountMode="Actual"
WaitMessageFont-Size="1.2em" ShowToolBar="true"
Visible="true"
InteractiveDeviceInfos="(Collection)">
<LocalReport></LocalReport>
</rsweb:ReportViewer>
I'm trying to integrate it with my toolbar that will also have functionalities provided by reportviewer toolbar. So I'm not using reportviewer's toolbar.
On my toolbar I have image and textbox:
<img src="img/search.png" alt="Find" onClick="findString()" />
<asp:TextBox id="txtSearch" runat="server"></asp:TextBox>
Here's my script:
function findString() {
var viewer = $("#ReportViewer1");
var searchText = document.getElementByID('<%=txtSearch.ClientID>');
if (!viewer.get_isLoading() && viewer.get_reportAreaContentType() == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
viewer.find(str);
}
return false;
}
function nextHit() {
var viewer = $("#ReportViewer1");
if (!viewer.get_isLoading() && viewer.get_reportAreaContentType() == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
viewer.findNext();
}
return false;
}
In function findString, I'm getting (I saw in firebug) isLoading is a property & not a function. Am I missing something?
If I change my function as:
function findString() {
var viewer = $("#ReportViewer1");
var searchText = document.getElementByID('<%=txtSearch.ClientID>');
viewer.find(str);
return false;
}
I don't see that error, but don't see the search text highlighted in the report. Help.
The issue is that no post back occurs. I noticed that if I returned true this would not be the be case .. however there were non-deterministic results so I am at a loss.
Any help appreciated!
<DropDownList ID="ddlS1" runat="server" onclick = "checkHighDegreeCompliance(this, 1);" SelectedIndexChanged = "ddlS1_SelectedIndexChanged" AutoPostBack="true" >
Here is the markup on the actual page after loading
<select name="rptrSection1$ctl00$rptrSection2$ctl00$ddlS2" class="DDLSelector2 SDropDown IsNormal" id="rptrSection1_ctl00_rptrSection2_ctl00_ddlS2" style="width: 200px;" onchange="checkHighDegreeCompliance(this, 2);setTimeout('__doPostBack(\'rptrSection1$ctl00$rptrSection2$ctl00$ddlS2\',\'\')', 0)">
Here is the javascript
function checkHighDegreeCompliance(obj, sectionNum)
{
var parDdl = $(obj);
var parCompLev = parDdl.attr('selectedIndex');
var pnlDiv = parDdl.parents('.Section');
var ddls = pnlDiv.find('.DDLSelector' + (sectionNum + 1));
ddls.each(function ()
{
var childDDL = $(this);
var childComLev = childDDL.attr('selectedIndex');
if (childComLev > parCompLev)
{
parDdl.attr('selectedIndex', childComLev);
}
if (sectionNum < 4)
{
checkHighDegreeCompliance(childDDL, ++sectionNum);
}
});
}
try with return keyword before the onclick event
<DropDownList ID="ddlS1" runat="server" onclick = "return checkHighDegreeCompliance(this, 1);" SelectedIndexChanged = "ddlS1_SelectedIndexChanged" AutoPostBack="true" >
Let me know if it not worked.