I'm using ASP calender. I want to show a popup when a user clicks the date,also I want to show the selected date in the popup. I used this link.
This is my asp calender
<div id='basic-modal'>
<asp:Calendar ID="cal" Width="700" OnDayRender="DayRender" BackColor="white" runat="server" OnSelectionChanged="cal_SelectionChanged" >
<SelectedDayStyle BackColor="#C00000" />
<DayStyle CssClass="basic" />
</asp:Calendar>
this is my pop up form.
<div id="basic-modal-content">
<table>
<tr><td>Date:</td><td>
<asp:Label ID="lblSelectDate" runat="server" Text=""></asp:Label></td>
</tr>
<tr><td>Message : </td><td>
<textarea id="txtMessage" cols="20" rows="2" ></textarea>
</td>
</tr>
<tr><td></td><td><input type="submit" value="Submit" /></td></tr>
</table>
</div>
when I click the date it shows popup , but It doesn't call the "cal_SelectionChanged" function.
protected void cal_SelectionChanged(object sender, EventArgs e)
{
lblSelectDate.Text = e.ToString();
}
So my problem is how to pass the selected date to popup?
This is a working code..
protected void cal_SelectionChanged(object sender, EventArgs e)
{
lblSelectDate.Text = cal.SelectedDate.ToString();
}
Related
I've been looking for this answer for a couple weeks now but many other questions/answers don't fit my project or simply don't work.
Let me explain my project.
It is a simple View Page which on page load it would set the Text to different fields throughout the page. On the bottom I have a container with buttons which control which div is displayed in the container. On each click of the button, I run some code to set data sources to grid views or fill fields with text. I noticed when I click F5 to refresh the page I get that pesky "form resubmission" popup which will cause the last button click such as appending a note to a listview to be duplicated.
Here is some code to understand what I am doing
HTML(Not complete, just necessary to understand my question)
<td style="vertical-align: top;" class="Flow-Sub-Menu">
<asp:Button ID="Button_Sub_Menu_Financial" runat="server" Text="Financial Info" OnClick="Button_Sub_Menu_Financial_Click" />
<asp:Button ID="Button_Sub_Menu_Indemnitors" runat="server" Text="Indemnitors" OnClick="Button_Sub_Menu_Indemnitors_Click" />
<asp:Button ID="Button_Sub_Menu_Court" runat="server" Text="Court Info" OnClick="Button_Sub_Menu_Court_Click" />
<asp:Button ID="Button_Sub_Menu_Forfeiture" runat="server" Text="Forfeiture Info" OnClick="Button_Sub_Menu_Forfeiture_Click" />
<asp:Button ID="Button_Sub_Menu_Collaterals" runat="server" Text="Collaterals" OnClick="Button_Sub_Menu_Collaterals_Click" />
<asp:Button ID="Button_Sub_Menu_Notes" runat="server" Text="Notes" OnClick="Button_Sub_Menu_Notes_Click" />
<asp:Button ID="Button_Sub_Menu_Documents" runat="server" Text="Documents" OnClick="Button_Sub_Menu_Documents_Click" />
</td>
<div id="Div_Sub_Menu_Notes" runat="server" visible="false">
<div class="row">
<div class="col-xs-4" style="min-width: 550px;">
<div class="Flow-Box">
<div class="Flow-Box-Content" style="height: 440px; overflow-y: scroll;">
<asp:ListView ID="LV_Notes" runat="server" ItemPlaceholderID="ItemPlaceHolder" DataKeyNames="Bond_Note_ID" OnPagePropertiesChanging="LV_Notes_PagePropertiesChanging" OnItemCommand="LV_Notes_ItemCommand">
<LayoutTemplate>
<table style="width: 500px; background-color: white;">
<tr id="ItemPlaceHolder" runat="server"></tr>
<tr>
<td colspan="2">
<asp:DataPager ID="DataPager_Notes" runat="server" PagedControlID="LV_Notes" PageSize="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td colspan="2" style="padding-left: 10px; padding-right: 10px;">
<div style="border: 2px solid grey; height: 75px; padding: 5px;">
<%# Eval("Note") %>
</div>
</td>
</tr>
<tr>
<td style="padding-left: 10px;" <%# (Eval("Document_ID").ToString() != "" ? "" : "hidden=\"hidden\"") %>>
<label>Document Attached : <%# Eval("Document_Title").ToString() %></label>
</td>
<td style="text-align: right; padding-right: 10px;" <%# (Eval("Document_ID").ToString() != "" ? "" : "hidden=\"hidden\"") %>>
<asp:Button ID="Button_View_Document" runat="server" Text="View/Download Document" CommandName="View_Document" CommandArgument='<%#Eval("Document_ID")%>' />
</td>
</tr>
<tr>
<td style="text-align: left; padding-left: 10px;">
<div>
<%# Convert.ToDateTime(Eval("Created_DateTime")).ToShortDateString() + " " + Convert.ToDateTime(Eval("Created_DateTime")).ToShortTimeString() %>
</div>
</td>
<td style="text-align: right; padding-right: 10px;">
<div>
<%# Eval("Full_Name") %>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="height: 20px; border-top: 4px solid #009900;"></td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4" style="min-width: 500px;">
<div class="Flow-Box">
<div class="Flow-Box-Label">
New Note
</div>
<div class="Flow-Box-Content">
<table class="Flow-Box-Table">
<tr>
<td>
<textarea id="TextArea_New_Note" runat="server" style="width: 400px; height: 150px;"></textarea>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button_Append_New_Note" runat="server" OnClick="Button_Append_New_Note_Click" Text="Append Note" />
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
C# Codebehind
protected void Button_Sub_Menu_Notes_Click(object sender, EventArgs e)
{
resetSubMenuButtons();
Button_Sub_Menu_Notes.BackColor = System.Drawing.Color.Orange;
Div_Sub_Menu_Notes.Visible = true;
string bondID = Request.QueryString["BondID"];
bindNotes(bondID);
}
protected void bindNotes(string bondID)
{
DataTable dt = Common_Functions.GetData("SELECT * FROM View_Bond_Notes_With_Name WHERE Bond_ID='" + bondID + "' ORDER BY Created_DateTime DESC");
LV_Notes.DataSource = dt;
LV_Notes.DataBind();
}
protected void LV_Notes_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
(LV_Notes.FindControl("DataPager_Notes") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
string bondID = Request.QueryString["BondID"];
bindNotes(bondID);
}
protected void LV_Notes_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (String.Equals(e.CommandName, "View_Document"))
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
string documentID = e.CommandArgument.ToString();
Session["BondDocumentID"] = documentID;
Page.ClientScript.RegisterStartupScript(GetType(), "openDocument", "window.open('/FileServing/Bond_Document_Server.aspx');", true);
}
}
protected void Button_Append_New_Note_Click(object sender, EventArgs e)
{
string bondID = Request.QueryString["BondID"];
string UserID = Request.Cookies["UserID"].Value;
string newNote = TextArea_New_Note.Value;
if (String.IsNullOrWhiteSpace(newNote))
{
return;
}
cmd = new SqlCommand("INSERT INTO Bond_Notes " +
"(Bond_ID, Created_DateTime, Created_By, Note) " +
"VALUES " +
"(#Bond_ID, #Created_DateTime, #Created_By, #Note)", conn);
cmd.Parameters.AddWithValue("#Bond_ID", bondID);
cmd.Parameters.AddWithValue("#Created_DateTime", DateTime.Now);
cmd.Parameters.AddWithValue("#Created_By", UserID);
cmd.Parameters.AddWithValue("#Note", (String.IsNullOrWhiteSpace(newNote) ? (object)DBNull.Value : newNote));
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
TextArea_New_Note.Value = "";
bindNotes(bondID);
}
So when the user clicks "Button_Append_New_Note", the code will fire to run the sqlcommand and then refreshes the ListView by calling the "bindNotes(bondID)". If the user clicks F5 or hits refresh for whatever reason, they are resubmitting that form and add duplicates. I've read many solutions to redirect to the same page, this will not work in my case since the div would be hidden again and I would prefer the Notes div to stay visible so the user can see their new note in the listview. I also prefer not to have an sql check to look for a duplicate and prevent an insert since I may want the user to insert duplicates if they chose to at another time, but the user would manually type in the duplicate.
Any recommendations or suggestions on how to avoid the form resubmission?
Also please no criticizing on the code, I am looking for answers, not a lecture on why its bad to build an SQL sentence with inline string addition. I will correct and optimize these faults eventually.
If you found my solution elsewhere, please ensure it would work in my case cause I have found my same question many times, but not with my scenario.
Thanks in advance.
As you probably know, ASP.NET Web Forms send POST requests back to the server and then re-render the Page in the same request. This is why we see the form re-submission message when we click "reload".
To avoid this issue, we should employ the post-then-redirect pattern used by many web applications. Here's a quick overview:
A user clicks a button which submits the form as a POST request.
The server receives the request and saves the data.
The server issues a redirect response along with any needed state.
The browser receives the redirect and loads the appropriate page by sending a GET request.
Because we redirect the browser to a new (or the same) location, this clears the POST data from the previous request so we can hit "reload" without re-submitting the same data again. The URL that we redirect to should contain only the data needed for the server to interpret what to display on the page. This pattern provides a durable way to maintain state between requests in HTTP.
To apply this to the Web Form in the question, we need to change some assumptions about how the page loads. Instead of binding the notes to the page after running each POST action, we'll redirect the user first, and then bind the notes:
protected void Button_Append_New_Note_Click(object sender, EventArgs e)
{
string bondID = Request.QueryString["BondID"];
// Save the new note...
Response.Redirect("http://example.com/Page.aspx?BondID=" + bondID);
}
Then, when the browser loads the redirect:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindNotes(Request.QueryString["BondID"]);
}
}
We'll need to change each of the post-back methods to use this pattern. Some of the methods may need to add additional parameters to the redirect URL that the page reads to configure the display.
This is quite easy and blocks the pop up asking for form resubmission on refresh once the form is submitted. Just place this line of javascript code at the footer of your file and see the magic.
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
I need help with Umbraco user control.
I create a user control to get input from user.
ascx file
<form id="formRegister" runat="server">
<table>
<tr>
<td>
<asp:TextBox ID="txtUserName" type="text" placeHolder="User Name" runat="server" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" ClientIDMode="Static" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>
the ascx.cs file
protected void Page_Load(object sender, EventArgs e)
{
var b = 0;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
var a = 0;
}
but somehow when it's loaded i get this in firebug
<form id="formRegister" action="/register/" method="post">
So the form create it's own action and do that action when I click the submit button instead of the btnSubmit_click event.
What should I do?
User controls won't fire their on click events when loaded as a macro in an Umbraco MVC site. Create a partial view and surface controller instead.
I am a new developer and I what I am trying to accomplish is hiding the radio buttons in the bottom DIV and the btnSetFinishState when clicked shows the bottom DIV (which it does from code behind). But the radio buttons when clicked do not fire the code behind method.
Here is .aspx:
<div class="row">
<asp:Button ID="btnSetFinishState" runat="server" Text="FINISHED" OnClick="btnSetFinishState_Click" UseSubmitBehavior="False" Enabled="False" />
</div>
<div class="row" id="finishedBlock" runat="server" visible="false">
<asp:Label ID="lblSetFinishText" runat="server" Text="Are you sure you want to set state to finished?" />
<div data-toggle="buttons" id="divRadioButtons">
<label id="btnFinishyes" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishyes" Text="Yes" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishyes_CheckedChanged" />
</label>
<label id="btnFinishno" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishno" Text="No" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishno_CheckedChanged" />
</label>
</div>
</div>
The aspx.cs code:
protected void btnSetFinishState_Click(object sender, EventArgs e)
{
// if neither radio button clicked
if (!finishyes.Checked && !finishno.Checked)
{
finishedBlock.Visible = true; // show the radio button DIV
//return;
}
}
protected void finishno_CheckedChanged(object sender, EventArgs e)
{
finishedBlock.Visible = false; // hide the radio buttons
finishno.Checked = false; // reset the no button to false
}
protected void finishyes_CheckedChanged(object sender, EventArgs e)
{
// set the finished state code
}
Is there e reason why btnSetFinishState is set to Enabled="False" ?
Because I tested this code and it works
aspx code
<div class="row">
<asp:Button ID="btnSetFinishState" runat="server" Text="FINISHED" OnClick="btnSetFinishState_Click" UseSubmitBehavior="False" Enabled="true" />
</div>
<div class="row" id="finishedBlock" runat="server" visible="false">
<asp:Label ID="lblSetFinishText" runat="server" Text="Are you sure you want to set state to finished?" />
<div data-toggle="buttons" id="divRadioButtons">
<label id="btnFinishyes" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishyes" Text="Yes" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishyes_CheckedChanged" />
</label>
<label id="btnFinishno" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishno" Text="No" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishno_CheckedChanged" />
</label>
</div>
</div>
aspx.cs
protected void btnSetFinishState_Click(object sender, EventArgs e)
{
// if neither radio button clicked
if (!finishyes.Checked && !finishno.Checked)
{
finishedBlock.Visible = true; // show the radio button DIV
//return;
}
}
protected void finishno_CheckedChanged(object sender, EventArgs e)
{
finishedBlock.Visible = false; // hide the radio buttons
finishno.Checked = false; // reset the no button to false
}
protected void finishyes_CheckedChanged(object sender, EventArgs e)
{
// set the finished state code
Response.Redirect("WebForm2.aspx");
}
I ran your code in my machine and found event's are firing exactly.
So , I think the different between your environment and mine may be <%# Page directive and missing AutoEventWireup="true" property.
Please share your Asp.net version and project info such as
is there any master pages or not.
UPDATE:
Please create a new sample web form application in visual studio and add a new web form say 'form1', paste your aspx and code behind to the newly added 'form1'. Test and if successfull then check the difference in aspx and code behind with your existing project.Also please let us know.
<asp:Button ID="btnCheckPatientID" CssClass="cssbutton" runat="server" Text="Check"
OnClick="btnCheckPatientID_Click" />
<asp:ModalPopupExtender ID="btnCheckPatientID_ModalPopupExtender" runat="server"
PopupControlID="panelCheckPatient" TargetControlID="hiddenTargetControlForModalPopup"
BackgroundCssClass="modalbackground" CancelControlID="btnClose">
</asp:ModalPopupExtender>
<asp:Button runat="server" ID="hiddenTargetControlForModalPopup" Style="display: none" />
<div id="panelCheckPatient" class="modalpopup" style="display: none">
<iframe id="iframeCheckPatient" class="csstable" runat="server" width="550px" height="485px" scrolling="auto">
</iframe>
<table>
<tr>
<td align="right">
<asp:Button ID="btnClose" runat="server" CssClass="cssbutton" Text="Close" />
</td>
</tr>
</table>
</div>
Serve Code
protected void btnCheckPatientID_Click(object sender, EventArgs e)
{
iframeCheckPatient.Attributes["src"] = "Check_Patient.aspx?patientID=" + txtPatientID.Text.Trim();
btnCheckPatientID_ModalPopupExtender.Show();
}
I have open an Ajax Modal popup on click of btnCheckPatientID.
In Modal Popup load an iframe which contains Check_Patient.aspx page.All working correctly.
In Check_Patient.aspx there is Pass button.
On click of button i have to return some value to parent page.
What should i do.
Search on google but cant find any help
You can use button postbackurl property where you need to specify your parent page address and on the parent page use the following code:
let say you have a textbox on your popup, you can use the same as folows
TextBox txtnew=(TextBox)PreviousPage.FindControl("id or name of control");
and then use its value OR create a property on popup page like
public string popupdata
{
get; set;
}
popupdata=your poppage value;
now access the same on parent page using
string str=PreviousPage.popupData.Tostring();
OR you can use cookies or session as your other options.
I'm trying to code a page where you can post a comment without reloading the whole page. The comments are displayed using a Repeater control. The template looks like this:
<asp:UpdatePanel runat="server" ID="commentsUpdatePanel" UpdateMode="Conditional">
<ContentTemplate>
<!-- Comments block -->
<div class="wrapper bloc content">
<h3><img src="img/comments.png" alt="Comments" /> Comments</h3>
<p><asp:Label ID="viewImageNoComments" runat="server" /></p>
<asp:Repeater ID="viewImageCommentsRepeater" runat="server">
<HeaderTemplate>
<div class="float_box marge wrapper comments">
</HeaderTemplate>
<ItemTemplate>
<div class="grid_25">
<span class="user"><%#Eval("username")%></span><br />
<span style="font-size:x-small; color:#666"><%#Eval("datetime") %></span>
</div>
<div class="grid_75">
<p align="justify"><%#Eval("com_text") %></p>
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</div>
<!-- Post comment block -->
<div class="wrapper bloc content">
<h3><a id="post_comment" name="post_comment"><img src="img/comment_edit.png" alt="Comments" /></a> Post
a comment</h3>
<p class="description">Please be polite.</p>
<p>
<asp:Label ID="postCommentFeedback" runat="server" />
</p>
<table border="0">
<tr>
<td valign="top">
<asp:TextBox id="postCommentContent" runat="server" TextMode="MultiLine"
MaxLength="600" Columns="50" Rows="15" Width="400px" />
</td>
<td valign="top">
<span style="font-size:x-small">BBCode is enabled. Usage :<br />
<b>bold</b> : [b]bold[/b]<br />
<i>italic</i> : [i]italic[/i]<br />
<span class="style1">underline</span> : [u]underline[/u]<br />
Link : [url=http://...]Link name[/url]<br />
Quote : [quote=username]blah blah blah[/quote]</span>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="postCommentButton" runat="server" Text="Submit"
onclick="postCommentButton_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
The postCommentButton_Click() function works just fine - clicking "Submit" will make the post. However, I need to completely reload the page in order to see new comments - the post the user just made will not show until then. I Databind the Repeater in Page_Load() after a (!isPostBack) check.
The postCommentButton_Click() function looks like this:
protected void postCommentButton_Click(object sender, EventArgs e)
{
// We check if user is authenticated
if (User.Identity.IsAuthenticated)
{
// Attempt to run query
if (Wb.Posts.DoPost(postCommentContent.Text, Request.QueryString["imageid"].ToString(), User.Identity.Name, Request.UserHostAddress))
{
postCommentFeedback.Text = "Your post was sucessful.";
postCommentContent.Text = "";
}
else
{
postCommentFeedback.Text = "There was a problem with your post.<br />";
}
}
// CAPTCHA handling if user is not authenticated
else
{
// CAPTCHA
}
}
In my case, we do see postCommentFeedback.Text refreshed, but, again, not the content of the repeater which should have one more post.
What is it I'm missing?
You should DataBind in the Page_Load within a !IsPostBack as you are. You should ALSO databind in your Click event.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
this.DataBind();
}
}
protected void MyButton_Click(object sender, EventArgs e)
{
//Code to do stuff here...
//Re DataBind
this.DataBind();
}
public override void DataBind()
{
//Databinding logic here
}
Instead of making your datasource a MySqlDataReader, have your reader populate a BindingList or something like that. Keep that in session and do your databind every non-postback and click. When your user posts, you can either add it to the list and wait for something to tell it to save that, but it makes more sense in the context of posting comments to save their post to your db and redo your datapull and stomp over your BindingList and re-Databind.
Also, personal peeve: I dislike <%#Eval....%>. Code in your page is usually a bad sign. Try using the Repeater.ItemDataBound Event
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
It sounds to me like the quick fix is to bind on page load regardless of postback. Alternatively, you could rebind from within postCommentButton_Click.
protected void Timer1_Tick(object sender, EventArgs e)
{
Repeater1.DataBind();
/*This is all I did for it to work.*/
}
protected void Buttontextbox_Click(object sender, EventArgs e)
{
this.DataBind();
/*Leave sql connection to your database above "this.databind"*/
}
try putting the update panel between tags and if you have already done that then check if the closing of div tags is proper