update of Date Textbox with calendar extender in gridview - javascript

Please friends help me out. I am trying to update a date column in my sql database. If i do it manually in edit mode in gridview it updates but when i use template field and attach ajax calendar extender it does not update but inserts null date into the database and eventually disappears from the gridview. Below is my code:
<%#Eval("HandoverDate","{0:dd/MM/yyyy}")%>
<EditItemTemplate>
<asp:TextBox ID="tbxDate" runat="server" Text='<%#Eval("HandoverDate","{0:dd/MM/yyyy}")%>'></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="tbxDate_CalendarExtender" runat="server" BehaviorID="tbxDate_CalendarExtender" TargetControlID="tbxDate" />
</EditItemTemplate>
</asp:TemplateField>

Related

asp.net Control visibility

I have a aspx form in which there are 5 controls below is the design code:
Question
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><br />
Answer
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
<asp:CheckBox ID="CheckBox1" runat="server" Text="If Other" AutoPostBack="True"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
A user selects a question from the drop down list and chooses the answer from the answer list.
If he/she doesn't find the answer in drop down list than he/she selects the checkbox and type the answer in textbox and press the submit button afterwards.
Is it possible to show the textbox and at the same time hide the drop down list using a single line code in checkbox OnCheckedChanged event?
Yes (though I'd use some more lines for better readability), you should set the visibility of the TextBox to false, to hide it at first:
<asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox>
In CheckBox1_CheckedChanged, you add the following lines:
DropDownList2.Visible = !CheckBox1.Checked;
TextBox1.Visible = CheckBox1.Checked;

How to get javascript array inside asp.net button click event?

net application. I have one gridview with checkboxes.Whenever checkbox is checked i want to send email to users. My columns of gridview are id,name,emailid etc. Whenever checkbox is checked i want to send email. I written javascript code to catch up all the emailids from gridview and pushing all the email ids to the array. I am confusing how to take these id's to the server side.
This is my button.
<asp:Button ID="Button1" class="submitLink blueButton" runat="server" Text="GETID" OnClientClick="javascript:sendEmail()" OnClick="Button1_Click" />
Using below line of code I am able to get the required email id's
$('#<%= gdvRegretletter.ClientID %> input[type="CheckBox"]').each(function () {
if ($(this).closest('tr').find('input[type="checkbox"]').prop("checked") == true)
email.push($(this).closest('tr').find('td:eq(3)').text().trim());
});
Array email will be capturing all the required email id's but i want these values inside the Button1_Click event in server side. May i have some idea to achieve this? Thank you for your time.
You could loop all the rows in the GridView and see which CheckBox has been checked. In this snippet the email address is also displayed in the GridView in a Literal, but there are a lot of other ways do get the email address, either from the GridView or it's original source.
<asp:GridView ID="GridView1" runat="server" DataKeyNames="Id">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("email") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Button1_Click(object sender, EventArgs e)
{
//loop all the rows in the gridview
foreach (GridViewRow row in GridView1.Rows)
{
//find the checkbox with findcontrol and cast it back to one
CheckBox checkbox = row.FindControl("CheckBox1") as CheckBox;
//is it checked?
if (checkbox.Checked == true)
{
//do the same for the label with the email address
Literal literal = row.FindControl("Literal1") as Literal;
string email = literal.Text;
//send email
}
}
}

How do I can get asp:Panel to work properly with asp:RadioButtonList without AutoPostBack?

I'm developping a form page in a WebForms application.
I have a RadioButtonList and a Panel, and I wanted the panel to open when a especific value of the RadioButtonList was selected, how do I do this?
I've tried with AutoPostBack but I didn't like how it worked (running the page again), are there any other solutions?
Some of the places I searched for an answer recommended using the AutoPostBack property, but I personally didn't like it and so I had to find another way for it to work and so I decided to use JavaScript/JQuery...
This is an HTML sample code of an example of a RadioButtonList and a panel that opens when a chosen option on it is clicked (the value "Required" causes it to open and "Not Required" to close in this case):
<div>
<p class="space">3.2. ACCOMMODATION (*)</p>
<asp:RadioButtonList ID="accomodation" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" Width="500px">
<asp:ListItem Text="Not Required" Value="Not Required"></asp:ListItem>
<asp:ListItem Text="Required" Value="Required"></asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="PanelAccommodation" runat="server">
<p>
Number of nights (*):
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="numberOfNights" ForeColor="red" ErrorMessage="<- Required"></asp:RequiredFieldValidator>
</p>
<asp:TextBox ID="numberOfNights" runat="server" Width="50px"></asp:TextBox>
<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="numberOfNights"
FilterType="Numbers" runat="server">
</ajaxToolkit:FilteredTextBoxExtender>
<p>Preferred Hotel:</p>
<asp:TextBox ID="preferredHotel" runat="server" Width="450px"></asp:TextBox>
<p>Preferred Hotel URL:</p>
<asp:TextBox ID="preferredHotelURL" runat="server" Width="450px"></asp:TextBox>
</asp:Panel>
</div>
The Script I used:
$(document).ready(function () {
$("#MainContent_PanelAccommodation").hide("fast");
$('#<%= accomodation.ClientID%>').find('input:radio').click(function () {
var selVal = $('#<%= accomodation.ClientID %>').find('input:checked').val();
if (selVal == "Required") {
$("#MainContent_PanelAccommodation").show("fast");
}
if (selVal == "Not Required") {
$("#MainContent_PanelAccommodation").hide("fast");
}
})
});
In this Script I use the first
$("#MainContent_PanelAccommodation").hide("fast");
to make sure that when the page runs the panel is hidden and will only open when/if "Required" is selected...
Another thing you may struggle with is what ID to put in the function since as you can see the panel ID is "PanelAccommodation", but the ID I use in the function is "MainContent_PanelAccommodation" since that's how it's recognized on your browser (to check this just select the panel's position and inspect element) you'll notice that the ID becomes "MainContent_PanelAccommodation" because it inherits from your asp:Content ContentHolderID...
Hope this helps ;) any questions just ask...

How to disable image button onlclick in asp.net?

I have a GridView in this GridView there is a column which I use to select date with the use of asp:CalendarExtender. I have multiple rows in GridView which are dynamically generated.
When I click the image button calender pops up and I choose my date.
In some rows I want the User to select date when he clicks image button of that row. sometime I don't want to allow him to select date.
When he tries to change the date or click on the image button, he should get alert message saying that you are not allowed to change the date.
I want to handle it from client side. So please suggest me how to do this.
this is the aspx code.
<asp:TextBox runat="server" ID="StartDateTime" CssClass="search_area_text_vm_small" onclick = "javascript:DateClick(this.id);"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/image3.jpg" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTime" PopupButtonID="Image1" Format="yyyy-MM-dd" ></asp:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="StartDateTime"
ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
You can make use of the OnClientDateSelectionChanged event of the CalendarExtender.
Use below code:
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTime" PopupButtonID="Image1" Format="yyyy-MM-dd" OnClientDateSelectionChanged="checkIfDateSelected()" >
</asp:CalendarExtender>
<javascript>
function checkIfDateSelected(){
var dateTextBox=document.getElementByid('StartDateTime');
if(dateTextBox!='')
{
alert ('Date once selected cannot be changed');
return false;
}
</javascript>
This will show the info pop up and prevent the form submission if the date has been selected already.

select datetime in gridview and change next textbox value upon date selection in gridview

Scenario is i have a date time column in grid view, upon selection on date time column i need to show calculated value in next column's text box in gridview
i am not able to calculate value on basis of date selection, although i am able to select the date through jquery and place it in textbox. but it is not changing the next textbox value upon basis of selection.
code is as under
<asp:TemplateField HeaderText="Issue Date">
<ItemStyle Width="140px" />
<ItemTemplate>
<asp:TextBox ID="txtIssueDate" runat="server" Width="110px" Text='<%#Eval("RequirementIssueDate") %>'
ReadOnly="true" class="Calender" OnTextChanged="txtIssueDate_TextChanged"></asp:TextBox>
<img id="imgIssueDate" src="../KelshawImages/calender.png" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Expiration Date">
<ItemStyle Width="140px" />
<ItemTemplate>
<asp:TextBox ID="txtExpiration" runat="server" Text='<%#Eval("RequirementExpirationDate") %>'
ReadOnly="true" class="Calender" Width="110px"></asp:TextBox>
<img src="../KelshawImages/calender.png" />
</ItemTemplate>
</asp:TemplateField>
Not 100% sure but I think that if you put the ReadOnly attribute on the control you will not be able to modify it in the textchanged event. Try removing the ReadOnly=True attribute and simply add the HTML disabled attribute to the control and give it a try.

Categories