I have a formview on my web page and I want to change formview mode. But I want to change this with javascript.
Is this possible?
i have a repeater which has buttons. And i have a button outside of repeater. when i click the button where is outside, it shows formview in popup. this formview has to be insert mode. And when i click the button where is on repeater, it shows formview in popup. this formview has to be edit mode. But i cant do this c#. may be if i do this with javascript, it will works
<asp:ToolkitScriptManager ID="toolkitmanager1" runat="server"></asp:ToolkitScriptManager>
<asp:LinkButton runat="server" ID="lnkFake" />
<asp:ImageButton ID="img1" runat="server" PostBackUrl="javascript:$find('popUpBehavior').show();"/>
<asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="popUpCompanyEmployee"
runat="server" PopupControlID="panel1"
TargetControlID="lnkFake" BehaviorID="popUpBehavior" CancelControlID="btnKapat">
</asp:ModalPopupExtender>
<asp:Panel ID="panel1" runat="server" CssClass="modalPopup">
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="fv1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID" DefaultMode="Insert">
<InsertItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text="ProductName"></asp:Label>
<asp:TextBox ID="txtProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:TextBox>
<asp:Label ID="lblQuantity" runat="server" Text="Quantity"></asp:Label>
<asp:TextBox ID="txtQuantity" runat="server" Text='<%# Eval("Quantity") %>'></asp:TextBox>
<asp:Label ID="lblUnitPrice" runat="server" Text="UnitPrice"></asp:Label>
<asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:TextBox>
</InsertItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text="ProductName"></asp:Label>
<asp:TextBox ID="txtProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:TextBox>
<asp:Label ID="lblQuantity" runat="server" Text="Quantity"></asp:Label>
<asp:TextBox ID="txtQuantity" runat="server" Text='<%# Eval("Quantity") %>'></asp:TextBox>
<asp:Label ID="lblUnitPrice" runat="server" Text="UnitPrice"></asp:Label>
<asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:TextBox>
</EditItemTemplate>
</asp:FormView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnKapat"/>
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnkapat" runat="server" Text="kapat"/>
</asp:Panel>
<asp:Repeater ID="rpr1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
<asp:Label ID="lblProductName" runat="server" Text='<%#Eval("ProductName") %>'></asp:Label>
<asp:Label ID="lblQuantity" runat="server" Text='<%#Eval("Quantity") %>'></asp:Label>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%#Eval("UnitPrice") %>'></asp:Label>
<asp:ImageButton ID="imgPopup" runat="server" PostBackUrl="javascript:$find('popUpCBehavior').show();" />
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:NET2ConnectionString %>' SelectCommand="SELECT * FROM [ProductsRA]"></asp:SqlDataSource>
Basically, changing the mode of a FormView reflects what controls (html) are rendered to the page.
So it could not happen purely on client-side. You could use an update panel , so only an asyn post backis done and only the form view html is refreshed.
Have a look for reference Formview
Documentation for reference here
Hope it clears your doubt a bit
Related
I have some data in this table. When i edit the Percentage, how can i get the value of the Supply Quantity?
Below is my ASPX code:
<asp:GridView ID="grdSupplierItem" runat="server" AutoGenerateColumns="False" CssClass="Gridview3">
<Columns>
<asp:TemplateField HeaderText="Supplier">
<ItemTemplate>
<asp:Label ID="lblAutoNum" Visible="false" Text='<%# Eval("AutoNum") %>' runat="server" />
<asp:DropDownList ID="ddlSupplier" runat="server" CssClass="form-control width250">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sequence">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:TextBox CssClass="form-control numbertext" onkeypress="return onlyNumber(event)" Width="80px" ID="txtSequence" Text='<%#String.Format("{0:n0}", DataBinder.Eval(Container.DataItem, "Sequence")) %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Percentage (%)">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:TextBox CssClass="form-control numbertext" onkeyup="javascript:text_changed(this);" ID="txtPercentage" AutoPostBack="false" OnTextChanged="txtPercentage_TextChanged" Text='<%# DataBinder.Eval(Container.DataItem, "SupplyPercentage") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Effective Date">
<ItemTemplate>
<asp:TextBox CssClass="form-control datepicker" ID="txtEffectiveDate" data-provide="datepicker" runat="server" Width="120px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Expired Date">
<ItemTemplate>
<asp:TextBox CssClass="form-control datepicker" ID="txtExpiredDate" data-provide="datepicker" runat="server" Width="120px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price(RM)">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:TextBox CssClass="form-control numbertext text-right" OnTextChanged="txtUnitPrice_TextChanged" onkeypress="return isNumber(event)" ID="txtUnitPrice" AutoPostBack="true" Text='<%# DataBinder.Eval(Container.DataItem, "SellingPrice") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supply Qty">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:TextBox CssClass="form-control numbertext text-right" OnTextChanged="txtSupplyQty_TextChanged" AutoPostBack="true" onkeypress="return isNumber(event)" ID="txtSupplyQty" Text='<%# DataBinder.Eval(Container.DataItem, "SupplyQty") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supply Value">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:TextBox CssClass="form-control numbertext text-right" OnTextChanged="txtSupplyValue_TextChanged" AutoPostBack="true" onkeypress="return isNumber(event)" ID="txtSupplyValue" Text='<%# DataBinder.Eval(Container.DataItem, "SupplyValue") %>' runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField Text="<img border=0 src=ImageFile/Delete1.gif>" CommandName="Delete">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
</Columns>
<RowStyle CssClass="gridrow" />
<SelectedRowStyle CssClass="gridheader" />
<HeaderStyle CssClass="gridheader" />
<AlternatingRowStyle CssClass="gridRowAlt" />
</asp:GridView>
I had tried with this JS and only manage to get the value of Percentage(%)
function text_changed(textObj) {
value = textObj.value;
var $otherInput =
textObj.closest('tr').find('input[id$="txtSupplyQty"]');
}
I need to do some calculation on the Javascript Code.
The ID for your <asp:TextBox /> will change once your client receives the page.
You'll need to get the client's text box ID in a different way if you're doing it in JavaScript. If you're using jQuery, it'll look something like this:
const textBox = $find('<%= txtSupplyQty.ClientID %>');
But beyond that, the web form controls do not support the onkeyup event listener like you have defined here.
If you really want to attach an onkeyup event, you'll have to either manually attach an event listener in a script block like I just mentioned above or you'll have to do it in your code behind.
If you're attaching an event listener in code behind, you can it to your Page_Load:
txtPercentage.Attributes.Add("onKeyUp", "text_changed(this)");
What I am trying to do is click a link and have my webpage open as a popup not go to the webpage.
<asp:GridView ID="caseloads" runat="server" AutoGenerateColumns="false" GridLines="None"
Font-Size="12.5px" BackColor="#FFFFFF" CssClass="mGrid" OnSorting="caseloads_Sorting"
AllowSorting="true">
<Columns>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<a id="popup" href='erAlerts.aspx?id=<%#Eval("ClientKey") %>'>View</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Client ID" SortExpression="ClientKey">
<ItemTemplate>
<asp:Label ID="clientKey" runat="server" Text='<%#Eval("ClientKey")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Full Name" SortExpression="ConsumerName">
<ItemTemplate>
<asp:Label ID="clientKey" runat="server" Text='<%#Eval("ConsumerName")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Program" SortExpression="pgmName">
<ItemTemplate>
<asp:Label ID="clientKey" runat="server" Text='<%#Eval("pgmName")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="House" SortExpression="phoneH">
<ItemTemplate>
<asp:Label ID="clientKey" runat="server" Text='<%#Eval("phoneH")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cell" SortExpression="phoneC">
<ItemTemplate>
<asp:Label ID="clientKey" runat="server" Text='<%#Eval("phoneC")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
So when I click "View" I want to be able to go to display my erAlerts.aspx.
I have tried a some but they either don't seem to work or they will open then redirect me to the page anyways after close.
I had a working one before but forgot to make a backup of it and for some reason I am lost. I can't for the life of me figure out how I did it.
I have checkbox in a gridview, when you click on the checkbox i need to show confirm message box.
i want to change the confirm message box button text from 'OK'/'cancel' to 'Yes'/No
For this i am using JQuery plugin http://www.invetek.nl/samples/confirmon/index.php
My gridView below
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
style="text-align:center" CellPadding="3" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
BorderWidth="1px" ForeColor="Black" Font-Bold="false" GridLines="Vertical" RowStyle-CssClass="GridRow"
OnRowCommand="GridView1_RowCommand"><%--OnRowDataBound="GridView1_RowDataBound"--%>
<AlternatingRowStyle BackColor="#F8F8F8" />
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_CarBrandID" runat="server" Text='<%# Eval("CarBrandID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" HeaderText="Brand Name" HeaderStyle-CssClass="header-center">
<ItemTemplate>
<asp:Label ID="lbl_CarBrandName" runat="server" Text='<%# Eval("CarBrandName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Active" HeaderStyle-CssClass="header-center">
<ItemTemplate>
<asp:checkbox ID="lbl_Active" runat="server" AutoPostBack="true" OnCheckedChanged="chkIsActive_CheckedChanged" Checked='<%# Eval("IsEnabled") %>'></asp:checkbox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="5%" HeaderText="Models" HeaderStyle-CssClass="header-center">
<ItemTemplate>
<asp:Button ID="img_Save" runat="server" OnClientClick="ShowModel()" CommandArgument='<%# Eval("CarBrandID") %>' CommandName="ShowCarModels" Width="100%" Text="Display Models" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
my JQuery for checkbox change
<script>
$(document).ready(function () {
$('input[id*=lbl_Active]').confirmOn('change', function (e, confirmed)
{
if (confirmed)
{
alert("1")
$(this).remove();
}
else
{ // Clicked no
alert("2");
}
});
});
</script>
I am getting the confirm box only once (first time) after page load, if i check uncheck again then the message box does not appear. i want for every click of checkbox i need the message box to show. please help me out.
i have content page in which i am selecting value from drop down on which gridview populate i am here showing my aspx page,
<div>
<table>
<tr>
<td>
<asp:DropDownList ID="ddlConsultant" runat="server"
AutoPostBack="True"
onselectedindexchanged="ddlConsultant_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
</td>
<td>
<asp:TextBox ID="txtActivatedOn" runat="server">
</asp:TextBox>
<a href="javascript:show_calendar('<%=txtActivatedOn.ClientID%>','<%=txtActivatedOn.Text%>');">
<img border="0" src="./Images/calendar.gif" alt="calendar" /></a>
</td>
<td>
</td>
<td>
<asp:Button ID="btnUpdateActivated" runat="server" Text="Update Date"
class="button" />
</td>
</tr>
</table>
<div id="grdWithScroll" style="OVERFLOW: auto" onscroll="SetDivPosition()">
<asp:GridView ID="gvProjects" runat="server" AutoGenerateColumns="False" Height="150px"
Width="225px" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="gvProjects_RowDeleting"
DataKeyNames="ID" ViewStateMode="Inherit">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chk_All" runat="server" AutoPostBack="true" OnCheckedChanged="chk_All_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_selector" runat="server" AutoPostBack="true" OnCheckedChanged="chk_selector_CheckedChanged" Checked='<%#bool.Parse(Eval("Proj_Flag").ToString() == "True" ? "True": "False") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_ID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProjectID" Visible="true">
<ItemTemplate>
<asp:Label ID="lblProjectID" runat="server" Text='<%# Bind("ProjectID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Order #">
<ItemTemplate>
<!-- <asp:Label ID="lblOrderNumber" runat="server" Text=''></asp:Label>-->
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<a href="javascript:openPopup('DsProjectDetail.aspx?mode=1&cid=<%# Eval("ID") %>&prj=<%#Eval("Title")%>' )">
<%--<%#Eval("Title")%>--%>
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label></a>
</ItemTemplate>
<ControlStyle Width="400px" />
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="CompletionDate">
<ItemTemplate>
<asp:Label ID="lblCompletionDate" runat="server" Text='<%# Bind("CompletionDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="ConsultantID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblConsultantID" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField DeleteImageUrl="~/Images/Delete.gif" ButtonType="Image" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</div>
<input type="hidden" id="XPos" runat="server" />
<input type="hidden" id="YPos" runat="server" />
<table>
<tr>
<td>
<asp:Button ID="btnAddProject" runat="server" CssClass="button" Text="New Project"
onclick="btnAddProject_Click" />
</td>
</tr>
</table>
</div>
Javascript i am using are,
<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("grdWithScroll").scrollTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("grdWithScroll").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
<script type="text/javascript">
window.scrollBy(100, 100);
function foo() {
alert("ddd");
if (grdWithScroll != null) alert(grdWithScroll.scrollTop);
}
</script>
and at the end of the page load event i am using,
Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "SetDivPosition();", true);
i have added this line in
<%# Page Language="C#" MaintainScrollPositionOnPostback="true" ...
and also added in webconfig,
<system.web>
<pages maintainScrollPositionOnPostBack="true" >
</pages>
</system.web>
getting help from this link,
http://stackoverflow.com/questions/12092150/maintain-scroll-bar-position-of-a-div-within-a-gridview-after-a-postback
One think i wanna mention that "onscroll="SetDivPosition()" in div tag showing me warning that on scroll is not valid attribute for div tag
But after doing all this its not working for me firstly i populate gridview with dropdown when grid populate it shows check box column too in all rows that on checked save check box value in database and post back occurs if i am at bottom of grid it scroll to the top after post back
Hopes for your suggestion
Thanks
I have a javascript attached to two textboxes in two cells of a GridView that populates automaticaly another two textboxes in the same cell while typing.
It works fine for the first text box, but I'm getting "Uncaught TypeError: Cannot set property 'value' of undefined" error when typing in the second textbox.
Here's my javascript:
function Sync(obj, idx) {
var cell = obj.parentNode;
cell.parentNode.cells[cell.cellIndex + 2].getElementsByTagName("input")[idx].value = obj.value;
}
GridView:
<asp:TemplateField HeaderText="Country Code">
<EditItemTemplate>
<asp:TextBox ID="txtCountryCode" runat="server" Text='<%# Eval("CountryCode") %>' OnKeyUp="javascript:Sync(this, 0);"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtCountryCode" ValidationExpression="\d{1,3}" EnableClientScript="false"
ErrorMessage="The Country Code must be 1-3 numeric digits!" runat="server"
ForeColor="Red" Font-Size="Smaller">
</asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCountryCode" runat="server" Text='<%# Eval("CountryCode") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewCountryCode" runat="server"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" ControlToValidate="txtNewCountryCode" ValidationExpression="\d{1,3}" EnableClientScript="false"
ErrorMessage="The Country Code must be 1-3 numeric digits!" runat="server"
ForeColor="Red" Font-Size="Smaller">
</asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Main Number">
<EditItemTemplate>
<asp:TextBox ID="txtMainNumber" runat="server" Text='<%# Eval("MainNumber")%>' OnKeyUp="javascript:Sync(this, 1);"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" ControlToValidate="txtMainNumber" ValidationExpression="\d{1,14}" EnableClientScript="false"
ErrorMessage="The Country Code must be 1-14 numeric digits!" runat="server"
ForeColor="Red" Font-Size="Smaller">
</asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblMainNumber" runat="server" Text='<%# Eval("MainNumber")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewMainNumber" runat="server"></asp:TextBox>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" ControlToValidate="txtNewMainNumber" ValidationExpression="\d{1,14}" EnableClientScript="false"
ErrorMessage="The Country Code must be 1-14 numeric digits!" runat="server"
ForeColor="Red" Font-Size="Smaller">
</asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone">
<ItemTemplate>
<asp:Label ID="lblPhone" runat="server" Text='<%# Eval("Phone") %>' Enabled="false"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
+
<asp:TextBox ID="txtPhoneCountryCode" runat="server" Enabled="false" Text='<%# Eval("CountryCode") %>' Width="30px"></asp:TextBox>
<asp:TextBox ID="txtPhoneMainNumber" runat="server" Enabled="false" Text='<%# Eval("MainNumber")%>' Width="100px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewPhone" runat="server" Enabled="false"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
The FooterTemplate related to your txtMainNumber textbox contains only 1 textbox txtNewMainNumber but you tried to set its 2nd textbox that does not exist, change the following
OnKeyUp="javascript:Sync(this, 1);"
with
OnKeyUp="javascript:Sync(this, 0);"