|
ASP.NET is request based, nothing happens until a request has been made from a client, so there is no automatic mechanism. You would need to create a Windows Service or use Scheduled Tasks on the server. Or do the same thing on a client machine that may call a webservice on your server.
No comment
|
|
|
|
|
I am working on a C# asp.net 2010 web form web page I just wrote. Right now I am getting the error
'Cannot add an entity that already exists'. I get that error on the following line of code: attPlanDataContext.SubmitChanges();
I am trying to write to a table that has one to many rows that relate to the main table. When I try to add the second row to the table, that is when the error occurs.
I am hoping you can suggest what I need to change to fix this error. The following is the code that is affected by this error:
[^]protected void submitbutton(object sender, EventArgs e)
{
if (!Page.IsPostBack)
return;
CustomerDataContext attDataContext = new CustomerDataContext();
Customer att = null;
att = new Customer();
InsertCustomer(att);
attDataContext.Customer.InsertOnSubmit(att);
attDataContext.SubmitChanges();
CustomerDataContext attPlanDataContext = new CustomerDataContext();
Plan attplan = null;
attplan = new Plan();
InsertPlans(attplan, att, attPlanDataContext);
}
protected void InsertCustomer(Customer att)
{
// fills in data here
}
protected void InsertPlans(Plan attplan,Customer att, CustomerDataContext attPlanDataContext)
{
for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{
if (ChkBoxLstPlan.Items[i].Selected)
{
attplan.Att_id = att.Att_id;
attplan.Number = ChkBoxLstPlan.Items[i].Value.Substring(0, 5);
// Update the database
attPlanDataContext.Plans.InsertOnSubmit(attplan);
attPlanDataContext.SubmitChanges();
}
}
}
[^]
|
|
|
|
|
I have setup a custom validator on a checkbox list 2010 C# asp.net control. The custom control does 'work', but I still have a question about it. When an item is not selected from the checkboxlist control, the OnServerValidate code is executed once the 'submit' button is clicked.
Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process?
I have one additional question that is once the OnServerValidate event is fired, the error message does not display. The display occurs once I have code in the 'submiton event' that says if (!Page.IsPostBack) return; I would think once the OnServerValidate event finishes executing, I error message should be displayed. The error message should not wait until the logic in the submit button fires. Thus can you tell me if this is ok and why? if this is not ok, can you tell me why not and possibly point me to a reference to solve this issue?
The following is the code I am referring to:
[^] <asp:CustomValidator ID="CustomValidatorContractNumber" runat="server" CssClass="errorStyle"
OnServerValidate="ValidateNumber" ValidateEmptyText="True"
EnableClientScript="False"
ErrorMessage="You must select at least one item.">
</asp:CustomValidator>
public void ValidateNumber(Object source, ServerValidateEventArgs args)
{
args.IsValid = false;
for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{
if (ChkBoxLstPlan.Items[i].Selected)
{
args.IsValid = true;
}
}
}
protected void submitbutton(object sender, EventArgs e)
{
if (!Page.IsPostBack)
return;
} [^]
|
|
|
|
|
Member 8217517 wrote: Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process?
Use client validation script of custom validator and enable Client side validation.
If you are validating at server side also, Do have a check property Page.Isvalid before doing any operation.
This property will return true only if all validators is passed else it will return true.
For details about asp.net validators, you can have a look to one of my post
Exploring ASP.NET Validators
|
|
|
|
|
hi , i want to change and save a html file at runtime using xmltextreader. it works fine on local host but after uploading website i get this error:
The underlying connection was closed: The connection was closed unexpectedly.
on:
File.Copy(source, pathToNewPost);
XmlTextReader txReader = new XmlTextReader(pathToNewPost);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(txReader);<------
|
|
|
|
|
do you have a try/catch handler around it all? my guess is that you are getting an exception on the following:
oujeboland wrote: File.Copy(source, pathToNewPost);
remember that when you run inside the scope of IIS you are using a different user account vs when you run it from your desktop through visual studio.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
i've changed my directory permissions at host's control panel to full control , and after copying the file i can enter it's address manualy and visit the htm page. so the error shouldn't be on file.copy mehod.
any points for me to know?
|
|
|
|
|
have you added the try/catch handler that I mentioned?? the connection is ending abruptly most likely due to an unhandled exception that is occurring.
my initial thought is that it is occurring in the copy operation and without the exception information it is kind of hard to figure out what is happening. contained in the exception will be a message describing what happened.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
after adding try/catch block the same error appears.
|
|
|
|
|
your exception will have everything you need to solve the problem. in it will be the stack identifying where .net was when the exception occurred as well as what the exception itself was.
just a reminder... the message about your connection ending abruptly was because of the exception and I am guessing when you added your try/catch block you ended the catch statement with a throw. you still have to do the engineering to solve the exception itself.
since I am not there to see the exception message and look at all your code I can only guide you towards finding the solution.
just a reminder the only reason this is working on your local machine and not on IIS is because of security and permission issues. when you run on your local machine you are using your own account vs IIS using a system account. there is tons of information out there for you to search on regarding IIS security and such.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
thank u for spending your time. i've added try catch block and i show the message of exception
like this :
catch(exception ex)
{
response.write(ex.message);
}
and the message is the same.
|
|
|
|
|
XMLTextWriter is a fast way to write a XML file to the disk drive.
In general, you use XMLTextReader to read an existing XML file, change the contents, serialize the data, and then call XMLTextWriter to write the file back to the disk drive.
With XMLTextReader, you have to have a template, that describes the format of the XML elements, like a XSD file, in which you can compile it into a class, that you reference in the read and write operations.
If you want to save a html file, you should build the file, and then write it with file. f.open. I don't remember exactly what the syntax is.
|
|
|
|
|
how about javascript codes. there are some jquery and javascript codes that the htm page most contains. by the way , if there's a problem with my codes why it works fine on local ?
|
|
|
|
|
I may be way off base here, for I really don't see the connection between the XML and creating a HTML page from scratch.
When you develop on your computer, you can test 2 ways, 1 is in the Web Dev, which is a debug version of IIS Server, it's wide open, and has no security features, so you can access anything in your Windows OS. The web dev doesn't care what your doing, it just lets you step through code to fix issues.
The other is to use the IIS Server that you can run in the Windows OS, which does have Security and boundaries, in which you code cannot modify the OS. It cares what you do, and will apply boundaries and borders to your executing code.
As for your code, there is not posted for a through inspection.
With web code, you have to open, read and then close real fast. Because it's multi-user. I suspect that you left something open, or something crashed, and you don't know about it, so the connection closed.
This is the proper code for using XMLTextReader and opening a xml file. It has been tested over time, and can handle up to 3 read and writes per second. I open the file, read it, and destroy the reader. Then I manipulate the data. You have to add Serialize Handlers during the read and write.
Dim DataLocation As String = Nothing
DataLocation = Context.Server.MapPath("~/App_Data/CompanyInfo/ShippingLocations.xml")
'XML Data routines go here
Dim request_serializer As New XmlSerializer(GetType(Shipping_Origin_Data))
AddHandler request_serializer.UnknownNode, AddressOf serializer_UnknownNode
AddHandler request_serializer.UnknownAttribute, AddressOf serializer_UnknownAttribute
Dim Reader As XmlTextReader = Nothing
Dim XmlRequest As New Shipping_Origin_Data
Try
Reader = New XmlTextReader(DataLocation)
XmlRequest = CType(request_serializer.Deserialize(Reader), Shipping_Origin_Data)
Reader.Close()
Reader = Nothing
Catch ex As Exception
FirstRecordFlag = True
End Try
This is the proper code for writing a file to the disk drive with XMLTextWriter. Notice how I open and read the file, and then close it. I manipulate the data, and then I open the file and write it, and destroy all the objects.
Dim serializer As XmlSerializer
serializer = New XmlSerializer(GetType(Shipping_Origin_Data))
Dim XmlResponse As New Shipping_Origin_Data
XmlResponse.Version = "1.4.2"
XmlResponse.CreationDate = DateTime.Now.ToString("yyyy-MM-dd")
XmlResponse.Geographic_Record = MyLocation
Dim response_serializer As XmlSerializer = Nothing
response_serializer = New XmlSerializer(GetType(Shipping_Origin_Data))
Dim response_writer As StreamWriter = Nothing
response_writer = New StreamWriter(DataLocation)
response_serializer.Serialize(response_writer, XmlResponse)
response_writer.Close()
response_writer = Nothing
request_serializer = Nothing
serializer = Nothing
Protected Sub serializer_UnknownNode(ByVal sender As Object, ByVal e As XmlNodeEventArgs)
Dim Context As HttpContext = HttpContext.Current
End Sub
Protected Sub serializer_UnknownAttribute(ByVal sender As Object, ByVal e As XmlAttributeEventArgs)
Dim Context As HttpContext = HttpContext.Current
Dim attr As System.Xml.XmlAttribute = e.Attr
End Sub
|
|
|
|
|
after 5 days the problem is not resolved.i will try this too. thank you all.
|
|
|
|
|
Multiple Session or Multiple User login in same website/webapp at same time
|
|
|
|
|
Is this a statement or a question? And already replied to in Q&A.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
modified 28-Oct-11 5:22am.
|
|
|
|
|
How to write code in Asp.net for Multiple User login in same website/webapp at same time. Please help me with the code.
|
|
|
|
|
The web server software handles sessions, and session id's. In asp.net, you just need to get the session id, and just work with that instance of the session. So for each session id, you write a session.add("login", true);, and the web server will handle the rest.
|
|
|
|
|
Since I am new to working with C# asp.net 2010, I am asking the question on how to validate a checkbox list control.
I am adding a new checkboxlist control to a new C# asp.net 2010 web page I am in the process of working on. I am loading the values of the checkbox list controls from values I obtain in a sql server 2008 r2 database.
However, I would like to validate that at least one item in the checkbox list control has actually been selected. I would like to use a validator like the 'required validator' , 'custom validator', or some other validator to make certain the user selected something. I will run the validation when the user clicks the submit button.
Thus how would you accomplish this goal I have for using the validators? If my preferred method does not work, how would you validate that a checkbox list control has been checked? I do not want to update the database until the user has selected something.
|
|
|
|
|
Hi,
Despite I'm not an ASP.NET specialist, I would create an extension method on the CheckBoxList class that would return whether any item is checked. Thus :
public static class CheckBoxListExtension
{
public static bool IsChecked(this CheckBoxList cbl)
{
ListItemCollection selectedItems = cbl.Items.Where(li => li.Selected);
return (selectedItems.Length > 0);
}
}
Then, in my code :
if (myCheckBoxList.IsChecked())
{
}
|
|
|
|
|
In my Opinion;
The validator you want to use is just javascript, and is very unreliable. They only work on text, but you can make them work on Dropdowns, but on dropdowns, you have to add a blank item, with a value of "--", to indicate that the user did not select anything. Those validators are a waste of time, in production applications, they will haunt you at night.
You have to decide if you want to validate on the server side or client side.
on the server side, which requires a round trip to the server, and consumes bandwidth,
int returnValue = cbDecide.SelectedValue;
if the interger is 0, then nothing was selected.
in JQuery on the client side, it pretty much the same. Remember that DropDown's, Radio Button Groups, Checkbox groups pretty much work the same. They all have a selected value.
So make sure the dom is loaded first, and then execute your script.
$(document).ready(function () {
var validationFlag = true;
var decide_Value;
decide_Value = $('[id*="_cb_Decide_Field"]').val();
if (decide_Value == "") {
validationFlag = true;
}
}
|
|
|
|
|
So I'm trying to have a textbox update during the run process of a backend powershell script. I have the script running correctly, threaded and returning info and updating the value of txtProgress.Text during the process. The problem is I am unable to get the partial postback to run and update the web page during this process. Any help would be greatly appreciated. Here is the code:
<table class="style1">
<tr>
<td>
<asp:Label ID="lblSpace3" runat="server" Width="75px"></asp:Label>
</td>
<td style="text-align: center">
<asp:UpdatePanel ID="upProgress" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click"
Text="Submit" />
<asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click"
PostBackUrl="http://uspmvvmt001/vrs/admins/admins.aspx" Text="Cancel" />
<br />
<br />
<asp:TextBox ID="txtProgress" runat="server" Height="250px"
TextMode="MultiLine" Width="500px"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtProgress" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td style="text-align: center">
<asp:Label ID="lblSpace4" runat="server" Width="75px"></asp:Label>
</td>
</tr>
</table>
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Addsnapin = "Add-PSSnapin VMware.VimAutomation.Core";
string ConnectVserver = "Connect-VIServer vcenter-us-002 -user USERNAME -password PASSWORD";
int cpus, memory, numdisks, disk1, disk2 , disk3, disk4;
string vc, cluster, vmname, os;
string vars, fname;
fname = CreateFileName(24);
string ScriptFile = "UNCPATH\\ProvisionVM.ps1";
string OutFile = "UNCPATH\\ProvisionVM-testout.ps1";
string LogFile = "UNCPATN\\" + fname + ".log";
string scriptText = ReadPowerShellScript(ScriptFile);
cpus = Convert.ToInt32(ddlNumProc.Text.ToString());
memory = Convert.ToInt32(ddlAmtMem.Text.ToString()) * 1024;
vc = txtVC.Text.ToString();
cluster = ddlCluster.Text.ToString();
vmname = txtVMName.Text.ToString();
os = ddlOS.SelectedValue.ToString();
numdisks = Convert.ToInt32(ddlNumDisk.Text.ToString());
vars = "$cpus=" + cpus + "\r\n";
vars += "$memory=" + memory + "\r\n";
vars += "$vc=\"" + vc + "\"\r\n";
vars += "$cluster=\"" + cluster + "\"\r\n";
vars += "$vmname=\"" + vmname + "\"\r\n";
vars += "$os=\"" + os + "\"\r\n";
vars += "$numdisk=" + numdisks + "\r\n";
vars += "$LogFile=\"" + LogFile + "\"\r\n";
switch(numdisks)
{
case 1:
disk1 = Convert.ToInt32(txtDisk1.Text.ToString()) * 1024;
vars += "$disk1=" + disk1 +"\r\n";
break;
case 2:
disk1 = Convert.ToInt32(txtDisk1.Text.ToString()) * 1024;
disk2 = Convert.ToInt32(txtDisk2.Text.ToString()) * 1024;
vars += "$disk1=" + disk1 + "\r\n";
vars += "$disk2=" + disk1 + "\r\n";
break;
case 3:
disk1 = Convert.ToInt32(txtDisk1.Text.ToString()) * 1024;
disk2 = Convert.ToInt32(txtDisk2.Text.ToString()) * 1024;
disk3 = Convert.ToInt32(txtDisk3.Text.ToString()) * 1024;
vars += "$disk1=" + disk1 + "\r\n";
vars += "$disk2=" + disk1 + "\r\n";
vars += "$disk3=" + disk1 + "\r\n";
break;
case 4:
disk1 = Convert.ToInt32(txtDisk1.Text.ToString()) * 1024;
disk2 = Convert.ToInt32(txtDisk2.Text.ToString()) * 1024;
disk3 = Convert.ToInt32(txtDisk3.Text.ToString()) * 1024;
disk4 = Convert.ToInt32(txtDisk4.Text.ToString()) * 1024;
vars += "$disk1=" + disk1 + "\r\n";
vars += "$disk2=" + disk1 + "\r\n";
vars += "$disk3=" + disk1 + "\r\n";
vars += "$disk4=" + disk1 + "\r\n";
break;
default:
break;
}
scriptText = scriptText.Replace("**VARIABLES**", vars.ToString());
runSpace.Open();
ThreadScript(Addsnapin, sender, e);
ThreadScript(ConnectVserver, sender, e);
ThreadScript(scriptText, sender, e);
runSpace.Close();
}
private void ThreadScript(string scriptText, object sender, EventArgs e)
{
Collection<PSObject> PSCollection = new Collection<PSObject>();
Collection<Object> PSErrorCollection = new Collection<Object>();
PipelineExecutor PExecutor = new PipelineExecutor(runSpace,scriptText);
PExecutor.Start();
while (PExecutor.PLine.PipelineStateInfo.State == PipelineState.Running)
{
switch (WaitHandle.WaitAny(PExecutor.Hand))
{
case 0:
Collection<PSObject> data = PExecutor.PLine.Output.NonBlockingRead();
if (data.Count > 0)
{
for (int cnt = 0; cnt <= (data.Count - 1); cnt++)
{
txtProgress.Text += data[cnt].ToString();
txtProgress.Text += "\r\n";
upProgress.Update();
}
}
if (PExecutor.PLine.Output.EndOfPipeline)
{
}
break;
case 1:
Collection<object> Errordata = PExecutor.PLine.Error.NonBlockingRead();
if (Errordata.Count > 0)
{
for (int count = 0; count <= (Errordata.Count - 1); count++)
{
PSErrorCollection.Add(Errordata[count]);
}
}
break;
}
}
PExecutor.Stop();
PExecutor.PLine.Dispose();
}
}
If you need more info, please ask.
|
|
|
|
|
Since this is the first 2010 asp.net webform application that I am writing in C#, I have a question. For this application, I am adding some web pages to the existing company website.
In this web app the user clicks the ' next button' when they have entered data on the first page. When the user clicks the next button, I do a Response.Redirect("~/programnnme.aspx"); for the user to proceed to the next web page for processing. However when the user starts processing on the second page, I need to display the values they entered in the database on the previous webpage.
Thus what is the best way to keep the values just entered available for the next web page? Can you explain this to me and/or give me a url that I can use as a reference?
I do not think using 'global' values is a good idea from what I have read on the internet.
|
|
|
|
|
what version of HTML is this targeted at??
in HTML5 you have the LocalStorage object where you can put all this information if you want. however, if on your first page you know you are without a doubt storing the information in the database then it sounds like you have already resolved your question.
for information on the HTML5 localStorage object I will let you google it as there are tons of articles out there explaining its use.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|