first
aspx:
<div class="row">
<div class="col-sm-2">
<asp:TextBox TextMode="Number" runat="server" ID="FromNum" placeholder="From"/>
</div>
<div class="col-sm-4">
<asp:TextBox TextMode="Number" runat="server" ID="ToNum" placeholder="To"/>
</div>
<div class="col-sm-2">
<asp:Button ID="BtnRec" Text="Go" runat="server" OnClick="Btn_Click" />
</div>
</div>
<div class="col-sm-2">
<asp:Label runat="server" ID="Indication" />
</div>
second
aspx.cs
protected void Btn_Click(object sender, EventArgs e)
{
DataTable dataTable = SqlHelper.Client.GetDataTable(sql);;
for (int i = 0; i < dataTable.Rows.Count; i++)
{
string conMun = ((int)dataTable.Rows[i]["ConfirmNum"]).ToString();
string subject = "No: " + conMun;
this.Indication.Text = (i + 1).ToString() + " of" + dataTable.Rows.Count;
this.SendEmail(subject, html, email); //mail
}
}
I need
Indication
to be constantly updated/refreshed by the number.
How can this be done?
Related
The goal is that as a user I can enter a string into a text box. That string is passed to the codebehind as a parameter to a stored procedure call and returns an alert in the window.
The following code is not executing the stored procedure or returning an alert.
Markup:
<script type="text/javascript">
$(function PageLoad() {
document.getElementById('<%= ValueHiddenField.ClientID%>.value' = '<%= RemoveTote_TextBox.ClientID%>')
});
</script>
<div id="RemoveToteForm" runat="server" class="col text-center">
<div class="row">
<div class="col text-center">
<h2><%: Title %></h2>
</div>
</div>
<asp:TextBox ID="RemoveTote_TextBox" runat="server" />
<br/>
<input type="submit" name="SubmitButton" value="Submit" onclick="PageLoad()" />
<asp:hiddenfield id="ValueHiddenField"
onvaluechanged="ValueHiddenField_ValueChanged"
value=""
runat="server"/>
</div>
</asp:Content>
Code Behind:
protected void ValueHiddenField_ValueChanged(object sender, EventArgs e)
{
string ntsh = ValueHiddenField.Value;
using (OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnectToClient"].ConnectionString))
{
OdbcCommand cmd = new OdbcCommand("{call usp_Remove_Tote (?)}", con);
OdbcParameter Tote_number = cmd.Parameters.Add("#Tote_number", OdbcType.Char);
Tote_number.Value = ntsh;
con.Open();
String result = cmd.ExecuteScalar().ToString();
con.Close();
if (result != "Success+")
{
Response.Write("<script>alert('" + result + "'); </script>");
}
else
{
Response.Write("<script>alert('" + result + "'); </script>");
}
}
}
I am trying to create a file upload control dynamically for updating word documents. I have the following code in my aspx page.
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" DataKeyNames="FilePath" EmptyDataText="No documents attached" >
<HeaderStyle BackColor="Purple" Font-Bold="true" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="FilePath">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="My Document" OnClick="lbDownloadDocument_Click"></asp:LinkButton>
<img src="Image/delete.jpg" alt="" onclick="AddFile()" /><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button2_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have the following code in my .cs page.
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
PostedFile.SaveAs(Server.MapPath("~/Files/") + FileName);
}
}
}
And my script is :
<script type="text/javascript">
var i = 1;
function AddFile() {
i++;
var div = document.createElement('DIV');
div.innerHTML = '<input id="file' + i + '" name = "file' + i + '" type="file" /><img src="~/Image/delete.jpg" alt="Remove" onclick = "RemoveFile(this)" />';
document.getElementById("divFile").appendChild(div);
}
function RemoveFile(file) {
document.getElementById("divFile").removeChild(file.parentNode);
}
</script>
But Somehow this code is not working. I don't have much idea of file upload control. Please help me with it. Should I use an Update panel ?
I have issue to disable/enable validators for newly add row to gridview which is in Update panel, If I remove Update panel then it's worked perfect, and If I add Update panel then it stops working. I have created sample page.
Default.aspx.
<head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('table > tbody > tr .wrapper [class*="onoff"] option:selected').each(function (index) { adjustValidators(this); }); $('[class*="onoff"] select').change(function () { adjustValidators($('option:selected', this)[0]); }); }); </script></head>
<ajax:ToolkitScriptManager runat="server" ID="RadScriptManager1" AsyncPostBackTimeout="18000"> </ajax:ToolkitScriptManager><asp:MultiView ID="MultiView1" runat="server"> <asp:View ID="group_Group1" runat="server"> <div class="group group1"> <asp:Button ID="btnNext0_top" runat="server" Text="Next >>" OnClick="btnNext_Click" ValidationGroup="surveyValidate0" /> <asp:UpdatePanel runat="server" ID="UPNew" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView runat="server" ID="repeatregion_RRSectionSS" RegionName="RRSectionSS" AutoGenerateColumns="False" GridLines="None" CellSpacing="-1" CssClass="rrsectionss"> <Columns> <asp:TemplateField> <ItemTemplate> <div id="wrapper_ONOFF" runat="server" class="wrapper onoff"> <div class='statement onoff' id="statement_ONOFF" runat="server"> Required Validator :</div> <div class='question onoff' id="questionlayer_ONOFF" runat="server"> <asp:DropDownList runat="server" ID="question_ONOFF" ValidationGroup="surveyValidate0" Data='<%# Eval("ONOFF") %>' Val='<%# Eval("ONOFF_selectedValue") %>'> <asp:ListItem Text="Off" Value="-1"></asp:ListItem> <asp:ListItem Value="1" Text="On"></asp:ListItem> </asp:DropDownList> </div> </div> <div id="wrapper_testsssss" runat="server" class="wrapper testsssss"> <div class='statement testsssss' id="statement_testsssss" runat="server"> Sample Text </div> <div class='question testsssss' id="questionlayer_testsssss" runat="server"> <asp:TextBox runat="server" ID="question_testsssss" type="shortans" Columns='40' ValidationGroup="surveyValidate0" Text='<%# Common.DecodeXML(Eval("testsssss")) %>'></asp:TextBox> <asp:RequiredFieldValidator ID="rfv_question_testsssss" runat="server" ValidationGroup="surveyValidate0" SetFocusOnError="true" EnableClientScript="true" ControlToValidate="question_testsssss" Display="Dynamic" Text="**" ErrorMessage="**" /> </div> </div> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Button runat="server" ID="btnAddClick" Text="Add Section" OnClick="btn_Click" /> </ContentTemplate> </asp:UpdatePanel> </div> </asp:View> <asp:View ID="group_Group2" runat="server"> <div class="group group2"> <asp:Button ID="btnPrevious1_top" runat="server" Text="<< Prev" OnClick="btnPrevious_Click" /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="surveyValidate1" /> </div> </asp:View> </asp:MultiView>
<script type="text/javascript"> function pageLoad(sender, args) { if (args.get_isPartialLoad()) { $('table > tbody > tr .wrapper [class*="onoff"] option:selected').each(function (index) { adjustValidators(this); }); } } function adjustValidators(ctrl) { var id = ctrl.parentNode.id.replace('_question', '_rfv_question').replace('ONOFF', 'testsssss') // alert(ctrl.value); if (ctrl.value == -1) { ValidatorEnable(eval(id), false) } else { ValidatorEnable(eval(id), true) } } </script>
Default.aspx.cs.
protected void Page_Load(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = (MultiView1.ActiveViewIndex == -1) ? 0 : MultiView1.ActiveViewIndex;
DataTable objData =new DataTable();
if (ViewState["data"] != null)
{
objData = (DataTable)ViewState["data"];
}
else
{
objData = new DataTable();
objData.Columns.Add("testsssss");
objData.Columns.Add("ONOFF");
objData.Columns.Add("ONOFF_selectedValue");
objData.Rows.Add(objData.NewRow());
ViewState["data"] = objData;
}
if (!IsPostBack)
{
repeatregion_RRSectionSS.DataSource = objData;
repeatregion_RRSectionSS.DataBind();
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex += 1;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex -= 1;
}
protected void btn_Click(object sender, EventArgs e)
{
DataTable objData = (DataTable)ViewState["data"];
objData.Rows.Add(objData.NewRow());
repeatregion_RRSectionSS.DataSource = objData;
repeatregion_RRSectionSS.DataBind();
ViewState["data"] = objData;
}
when Click on add then item get added to gridview but validators are not disabled.
Thanks and Regards
Sadiq Modan
After some research and trickery I found the solution: replace eval in ValidatorEnable(eval(id), false) with document.getElementById(id). It worked for me.
I have the following code and i want the value entered by the ser in the prompt box to the textbox which is a asp.net control how do i do that? Please help.
protected void btnPreview_Click(object sender, EventArgs e)
{
divTemplateDesigner.Visible = true;
divQueryBuilder.Visible = false;
int count = 0;
string[] splitMessage = txtTemplate.Text.Split(' ');
List<string> parameterList = new List<string>();
List<string> valueList = new List<string>();
string newMessageString = txtTemplate.Text;
for (int i = 0; i < splitMessage.Length; i++)
{
if (splitMessage[i].StartsWith("["))
{
parameterList.Add(splitMessage[i]);
count++;
}
}
for (int j = 0; j < count; j++)
{
string message ="Enter "+parameterList[j];
Label lblmsge = new Label();
lblmsge.Text =
"<script language='javascript'>" + Environment.NewLine + "window.prompt('" + message + "')</script>";
Page.Controls.Add(lblmsge);
}
}
The prompt box is coming properly. But am not able to capture the value entered by the user.
And the HTML goes like this
<div class="page" runat="server" id="divTemplateDesigner">
<table bgcolor="#0CB1C0" style="width:100%;">
<tr>
<td bgcolor="White" class="style5" rowspan="2">
<asp:TreeView ID="treeviewDataset" runat="server"
onselectednodechanged="treeviewDataset_SelectedNodeChanged">
</asp:TreeView>
</td>
<td>
<asp:TextBox ID="txtTemplate" runat="server" Height="200px"
TextMode="MultiLine" Width="370px"></asp:TextBox>
</td>
<td colspan="2">
<br />
<br />
<asp:Button ID="btnPreview" runat="server" BackColor="White" Height="30px"
Text="Preview" Width="120px" onclick="btnPreview_Click" />
</td>
<td>
<asp:TextBox ID="txtPreview" runat="server" Height="200px" TextMode="MultiLine"
Width="370px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:Button ID="btnBack" runat="server" BackColor="White" Height="30px"
Text="Back" Width="120px" onclick="btnBack_Click" />
you see in this image that box has three placeholders [patient_ID] [Doctor_ID] and [Appointment_Date]
Am opening prompt boxes depending on the number of placeholders in the first box.
Count = number of placeholders
Just use Javascript to accomplish what you are after, instead of a postback to the server.
<script type="text/javascript">
function PromptAndFillPreview() {
var templateStr = document.getElementById('<%= txtTemplate.ClientID %>').innerText;
var previewStr = '';
var phIndexStart = templateStr.indexOf('[');
var phIndexEnd = 0;
while (phIndexStart >= 0) {
previewStr = previewStr + templateStr.substring(phIndexEnd, phIndexStart);
phIndexEnd = templateStr.indexOf(']', phIndexStart) + 1;
var placeholder = templateStr.substring(phIndexStart, phIndexEnd);
previewStr = previewStr + prompt("Please input value for " + placeholder, '');
phIndexStart = templateStr.indexOf('[', phIndexEnd);
}
previewStr = previewStr + templateStr.substring(phIndexEnd, templateStr.length);
document.getElementById('<%= txtPreview.ClientID %>').innerText = previewStr;
}
</script>
And since you don't need the postback, you can replace:
<asp:Button ID="btnPreview" runat="server" BackColor="White" Height="30px"
Text="Preview" Width="120px" onclick="btnPreview_Click" />
with:
<input type="button" style="background-color:White; height:30px; width:120px;"
value="Preview" onclick="PromptAndFillPreview()" />
Forgive my English, I had one challenge in my project I,e whenever I started to access hidden field value which in grid view using JavaScript or Jquery, I'm getting compilation error like hidden field doesn't exist in current context so how can I access hidden field value?
SelectPatientInfo.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="Server">
<script type="text/javascript">
function DispValue(sender, e) {
var id = e.get_value();
document.getElementById("<%=PatientRefferalId.ClientID%>").value=id; //getting error here
}
</script>
<div align="left" style="float: left; margin-left: 5px;">
<asp:GridView ID="gvPatient" runat="server" AutoGenerateColumns="false" EnableViewState="true">
<Columns>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="12px" HeaderStyle-Height="20px">
<HeaderTemplate> Patient Name </HeaderTemplate>
<ItemTemplate>
<asp:HiddenField ID="PatientRefferalId" runat="server" Value="0" />
<PUC:PatientUserControl ID="pucPatient1" runat="server" OnClientSelect="DispValue" PTStatusShow="0"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:Content>
SelectPatientInfo.aspx.cs
protected void Page_Load(object sender, EventArgs e) {
try {
if (!IsPostBack) {
dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt = AddRow(dt);
gvPatient.DataSource = dt;
gvPatient.DataBind();
}
} catch (Exception ex) {
}
}
private DataTable AddRow(DataTable dt) {
for (int i = 0; i < 5; i++) {
DataRow dr = dt.NewRow();
dr[0] = "";
dr[1] = ""; dt.Rows.Add(dr);
}
return dt;
}
protected void GridPatient_DataBound(object sender, EventArgs e) {
try {
foreach (GridViewRow item in gvPatient.Rows) {
HiddenField hfReferralId = (HiddenField)item.FindControl("PatientRefferalId");
Response.write(hfReferralId.Value);
}
} catch (Exception ex) {
}
}
I'm not sure the code
document.getElementById("<%=PatientRefferalId.ClientID%>")
will work, because you don't have only one "PatientRefferalId", but you get many (as many as numbers of rows in your gridview).
I don't know if there is a cleaner way, but I can do what you want by using this javascript code
var gv = document.getElementById("<%=gvPatient.ClientID%>");
var Rows = gv.getElementsByTagName("tr"); // Get all the rows from your gridview (rendered as html table).
// you can loop through the rows or if you know the row index, you can do:
alert(Rows[2].childNodes[0].children[0].value); // Show you the first control (the hiddenfield) of the first cell of the row #2.
Hi This post may help you.
var c = document.getElementsByTagName("table");
for (var i = 0; i < c.length; i++) {
if (c[i].id.indexOf("GridView1") > -1) {
var hidd = c[i].getElementsByTagName("input");
for (var j = 0; j < hidd.length; j++) {
if (hidd[j].type == "hidden")
alert(hidd[j].id);
}
}
}
And also refer following link .. its working to me..
http://forums.asp.net/p/1510265/3603566.aspx/1?Re+how+to+find+gridview+hidden+label+value+from+javascript
<asp:Content ID="Content2" ContentPlaceHolderID="cphContent" runat="Server">
<script type="text/javascript">
function DispValue(btnShow) {
var parentRow = $(btnShow).closest("tr");
var hiddenField=parentRow.find('input[id$=PatientRefferalId]');
alert(hiddenField.val());
return false;
}
</script>
<div align="left" style="float: left; margin-left: 5px;">
<asp:GridView ID="gvPatient" runat="server" AutoGenerateColumns="false" EnableViewState="true">
<Columns>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="12px" HeaderStyle-Height="20px">
<HeaderTemplate> Patient Name </HeaderTemplate>
<ItemTemplate>
<asp:HiddenField ID="PatientRefferalId" runat="server" Value="0" />
<asp:LinkButton ID="lnkPopUp" runat="server" Style="font-size: 16px;" OnClientClick="return DispValue(this)" Text="PopUp"
></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:Content>