I know people have asked this over the Internet before but i have not used ant Javascript and have done it very basic.
Basically when they click an (ImageButton)icon next to a Textbox it will trigger an OnClick event in the C# which will make the Calender visable. Then when they selected anything on that calender it will trigger SelectionChanged on c# agian and then will set the date they clicked on in a Textbox.
HTML
<input id="txt_DateOfInterview" type="Date" class="aclass" runat="server" />
<asp:ImageButton runat="server" imageurl="~/Images/Calender.png" id="calendericonDOI" CssClass="calendericonDOI ClanderDOI" OnClick="calendericonDOI_Click" ></asp:ImageButton>
<asp:calendar runat="server" ID="ClanderDOI" CssClass="ClanderDOI" OnSelectionChanged="ClanderDOI_SelectionChanged" BorderColor="#6a3d98">
<TitleStyle BackColor="Orange"/>
</asp:calendar>
C#
protected void calendericonDOI_Click(object sender, ImageClickEventArgs e)
{
ClanderDOI.Visible = true;
}
protected void ClanderDOI_SelectionChanged(object sender, EventArgs e)
{
txt_DateOfInterview.Value = ClanderDOI.SelectedDate.Date.ToString("d");
ClanderDOI.Visible = false;
}
Question: How can I make the calender stay visable when they click to see next month only.
Your sample code works as you expect. When you change selected month it does not trigger 'SelectionChange' event.
There is separate event for month change (VisibleMonthChanged) where you can hide calendar, but to achieve what you want just make sure that you do not hide calendar somewhere else in your code:
protected void ClanderDOI_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
ClanderDOI.Visible = true;
}
Using this code
Calendar will not show at Page Load
Calendar will show when you will Click SelectDate(btnSelectDate) Button
Calendar Will disappear after date selection
Calendar will not disappear on next month selection
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Calendar1.Visible = false;
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Calendar1.Visible = false;
}
protected void btnSelectDate_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
}
Related
I have two sites in one of them i have a textbox and on the other site i have a label. What i want to do is have the value that is written in the textbox be passed on to the label in the next website on a button click.
Website1.aspx (with the textbox)
protected void btnSpara_Click(object sender, EventArgs e)
{
}
The textbox:
<asp:TextBox ID="tbxKommentar" runat="server" OnTextChanged="tbxKommentar_TextChanged"></asp:TextBox>
Website2.aspx (with the label)
<asp:Label ID="lblKommentar" runat="server"></asp:Label>
How would i go about doing this.
So what you are asking is how to pass value from one page to another. There are several options and all of them are described here https://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
Code sample:
protected void btnSpara_Click(object sender, EventArgs e)
{
Response.Redirect("Website2.aspx?txt="+ tbxKommentar.Text);
}
In your Website2.aspx:
protected override void OnInit(EventArgs e){
lblKommentar.Text = Request.Params["txt"];
}
I can access the calendar control inside the Gridview Footer Template.
But it's not so easy to do the same thing in the EditItem Template
Can anybody suggest how to do this?
I am using 3 controls in the EditItem Template: Calendar, ImageButton, TextBox
as well as the Footer Template.
You can use the FindControl method in FooterRow of GridView to make the calendar visible True/False
protected void MyDateInsButton_Click(object sender, EventArgs e)
{
if (GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible == false)
{
GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = true;
}
else
{
GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = false;
}
}
And get the selected date inside the Footer TextBox
protected void MyDateInsCalendar_SelectionChanged(object sender, EventArgs e)
{
Calendar MyCal = (Calendar)sender;
((TextBox)GridView1.FooterRow.FindControl("txtinsMyDate")).Text = MyCal.SelectedDate.ToString("d");
GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = false;
}
How do you access the calendar control in the EditItem template to make it visible True and False?
protected void MyUpdButton_Click(object sender, EventArgs e)
{
}
The GridView1_RowUpdating method will work for getting the selected date from the calendar control into the textbox control, but I still want to make the calendar appear and disappear when the user presses the image button.
Any help is appreciated.
Thanks.
You are almost there. Do like this:
protected void MyUpdButton_Click(object sender, EventArgs e)
{
var MyDateInsCalendar = GridView1.Rows[GridView1.EditIndex].FindControl("MyDateInsCalendar") as Calendar;
MyDateInsCalendar.Visible = false;
}
And in GridView1_RowEditing, set EditIndex, rebind data:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = MyDataSource; //Set it to your datasource
GridView1.DataBind();
}
Hope it helps!
I use a gridview to display the search result. After clicking search button, the gridview will show page 1, but when I click page 2 link, the gridview disappeared and it was back when I click search button again and show page 2's content.
here is my code
<asp:GridView ID="searchresult" runat="server" AutoGenerateColumns="true" AllowPaging="true" OnRowDataBound="searchresult_RowDataBound" OnPageIndexChanging="searchresult_PageIndexChanging"
HeaderStyle-BackColor="#f9e4d0"
HeaderStyle-Height="20px"
Font-Size="11px"
AlternatingRowStyle-BackColor="#cfdfef"
Width="800px" style="text-align:left">
</asp:GridView>
and code behind
protected void search_Click(object sender, EventArgs e)
{
List<someclass> totalResult = new List<someclass>();
..... //some code to generate the datasource
searchresult.DataSource = totalResult;
searchresult.AllowPaging = true;
searchresult.DataBind();
}
protected void searchresult_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void searchresult_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
searchresult.PageIndex = e.NewPageIndex;
DataBind();
}
I have no idea why the page 2 won't show up until I click search button again. when I clicked the page 2 link, the page did postback but the RowDataBound event was not fired
You have to give your grid a datasource. It appears you are only doing this on search_Click, so your grid is only going to have data then. Try something like:
protected void search_Click(object sender, EventArgs e)
{
PopGrid();
}
protected void searchresult_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
searchresult.PageIndex = e.NewPageIndex;
PopGrid();
}
protected void PopGrid()
{
List<someclass> totalResult = new List<someclass>();
..... //some code to generate the datasource
searchresult.DataSource = totalResult;
searchresult.AllowPaging = true;
searchresult.DataBind();
}
searchresult_PageIndexChanging event handler will make that functionality work. However I recommend you use a gridview control inside a Panel with vertical scroll bar. My user love it and it is a lot faster moving up and down the gridview without defining any page index changing.
I hope it work for you.
I am facing problem in query string. Following is my asp code
<asp:Label ID="Lable1" runat="server" Text="" ></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
C# code:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Lable1.Text += Request.QueryString["refresh"] ;
Response.Redirect("QueryString1t.aspx?refresh=" + 1 + "");
}
Up to my knowledge Lable1 text should change on button click every time. Lable1 text should not show any thing on page load . on button click it should be like for first click 1 for second click 11 and so on..
But it is not showing as my expectation .So tell me please where i am wrong?
You are redirecting after setting label text, wrong approach.
Try this: -
protected void Page_Load(object sender, EventArgs e)
{
Lable1.Text = Request.QueryString["refresh"];
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("QueryString1t.aspx?refresh=" +
string.IsNullOrEmpty(Request.QueryString["refresh"]) ? 0 :
Convert.ToInt32(Request.QueryString["refresh"]) + 1 + "");
}
OR this: -
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Lable1.Text = string.IsNullOrEmpty(Lable1.Text) ? "0" :
(Convert.ToInt32(Lable1.Text) + 1).ToString();
}
Have a look at this:
http://msdn.microsoft.com/en-us/library/ms178472.aspx
Particularly the fourth and fifth events in the cycle.
If you want the text to be updated as you are looking for there, then you need to put that code in the page load, not the click event handler.
In brief, you have to think of it like this: Every time you do a redirect, you lose viewstate,
http://msdn.microsoft.com/en-us/library/ms972976.aspx
which is the means by which ASP.NET keeps track of your updates to the controls, like in your event handler. So your update is immediately lost.
The next piece of code you will hit is your load event, so that is where you need to set the label's text property.
How do I persist the value of a label through a response.redirect?
I am using Visual Studio 2010, and I created a site (.aspx).
I have 2 radiobuttons, and a DropDownList.
I want to have an invisible dropdownlist and whenever I click on the one radiobutton then the downdownlist to appear!
I have added a code like this but nothing changes and I can't understand why!!
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
DropDownList4.Visible = true;
else
DropDownList4.Visible = false;
}
protected void Page_Load(object sender, EventArgs e)
{
DropDownList4.Visible=false;
}
The only thing I am getting, is an invisible dropdownlist than never becomes visible!
Both of my radiobuttons have the same action "radiobutton_checkedchanged" ..
Thank you!
your code is ok , set AutoPostBack property of radiobutton to true
since RadioButton_CheckedChanged(object sender, EventArgs e) events occurs after page load
it will work no need for checking !IsPostBack
Modify your code as below:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DropDownList4.Visible=false;
}
}