I am new person in asp.net. I have one text box and one calender image button in my asp.net application. I use the masked extender to display date in the textbox like yyyy-mm--dd. Also i use the calender extender for the purpose of clicking image button it will show the date in the textbox. I use the following code.
<asp:ImageButton ID="imgdatefrom" runat="server"
ImageUrl="~/images/calendar.jpeg" Height="19px" Width="20px" />
<asp:Label ID="lblTo" runat="server" Text="End Date"
ForeColor="Black" Font-Size="Small"></asp:Label>
<asp:Label ID="enddateval" runat="server" ForeColor="Red" Text="*"></asp:Label>
<asp:CalendarExtender ID="txtDateFrom_CalendarExtender" runat="server" TargetControlID="txtDateFrom" Format="yyyy-MM-dd" PopupButtonID="imgdatefrom"
TodaysDateFormat="yyyy d, MMMM">
</asp:CalendarExtender>
While I executing that code and selecting date by clicking image button the selected date will not displayed in the textbox. Can anyone know how to solve the problem.
Thank you
Instead of MaskedExtender you just use standard TextBox Control. It will work.
Related
I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.
Can someone help me what's going on?
Here is the code:
<asp:TextBox ID="Textbox1" runat="server" Width="150px" TabIndex="6" MaxLength="8"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox> 
<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'" Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" />
Check the postback in the page_load function.
if(!Page.IsPostBack) {
}
I think you are loosing information on post back. The data is changed, but it get reset on post back.
I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.
Can someone help me what's going on?
Here is the code:
<asp:TextBox ID="Textbox1" runat="server" Width="150px" TabIndex="6" MaxLength="8"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox> 
<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'" Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" />
Check the postback in the page_load function.
if(!Page.IsPostBack) {
}
I think you are loosing information on post back. The data is changed, but it get reset on post back.
I am using calendar extender to create a popup textbox when a user click in a specific textboxk:
<asp:Label ID="searchDateFromLabel" runat="server" Text="From:"></asp:Label>
<asp:TextBox ID="searchDateFrom" runat="server" ></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="fromCalendarExtender" TargetControlID="searchDateFrom" runat="server">
</ajaxToolkit:CalendarExtender>
<asp:Label ID="searchDateToLabel" runat="server" Text="To:"></asp:Label>
<asp:TextBox ID="searchDateTo" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="toCalendarExtender" TargetControlID="searchDateTo" runat="server">
</ajaxToolkit:CalendarExtender>
Additionally, I populate the textboxes with default dates on page load:
fromCalendarExtender.SelectedDate = DateTime.Today.AddDays(-30);
toCalendarExtender.SelectedDate = DateTime.Now;
The issue I am having is that when a user clicks a textbox that is populated, it won't let them choose another date (other than the one the texbox was populated with) unless they first delete the text currently in the box.
How do I allow them to select any date?
Set PopupControlID to the TextBox you are trying use to select the date. It should then force the data-selector to pop up whenever the user gives focus to the TextBox.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="146px"
Width="308px">
<Columns>
<asp:TemplateField HeaderText="Original Price" ControlStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtOriginalPrice" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtOriginalPrice"
ValidationGroup="GridView1" Display="Static" ErrorMessage="" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am using above code but its not working though I have put requirefield validator it does not show me the '*'
Yes, your requiredfieldvalidator is certainly there, and it knows which control to validate.What is missing is "when to validate that control".And to answer this question you need to add your textbox the same ValidationGroup with your requiredfieldvalidator and also the control(this can be a button for example) causes to do a validation.So your code will be like
<%--<asp:Button ID="Button1" runat="server" ValidationGroup="GridView1" Text="Benjamin"...Somewhere in your code--%>
<asp:TextBox ID="txtOriginalPrice" runat="server" ValidationGroup="GridView1"></asp:TextBox>
So don't forget these question
What to validate?(a textbox)
When to validate?(after a button click)
After what action try to validate?(a button click)
With what to validate?(a requiredfieldvalidator)
All of these controls must have the same ValidationGroup.
In case you need the validation to be performed then check for something like this
<asp:Button ID="btnAdd" runat='server' ValidationGroup='GridView1' CausesValidation='true'.....
So now when you click the add button it will validate for those controls falling under the validation group you mentioned else the default value is "" hence you won't find any validation triggered.
Add ValidationGroup to TextBox (txtOriginalPrice), Button and other controls.
I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.