|
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
|
|
|
|
|
|
sc steinhayse wrote: I need to display the values they entered in the database on the previous webpage.
If the values have been stored in the database then all you need to do is extract them from that database and display. You could pass an id from page1 to page2 via the methods mentioned by Abhinav S that could be used to retrieve the record(s). Since the data is stored already there would be no need to actually pass it from page to page.
As for the database access and display, there are many resources here, and on the web, that demonstrate it.
No comment
|
|
|
|
|
You have to change the way you think about web pages.
Each web page, is a brand new instance of the program, fresh and clean.
The page has no clue what happened 10 minutes ago, or what the last page was.
You can pass data back to the web server using some html post, in which you you transmit back some values, but that's a waste of time.
You need to establish something common to each page, like a querystring that holds the value of the name, order number, sessionid, just something.
For each new page that loads, you start all over again at the begining, loading the data needed to make the page work.
You do this in the Page.Load Cycle of the web page.
Context HttpContext = HttpContext.Current;
If Not Context.Request.QueryString("cid") Is Nothing Then
SecureCustomerID = Context.Request.QueryString("cid")
CustomerID = Convert.ToInt32(SecureQueryString.Decrypt(SecureCustomerID.Replace(" ", "+")))
SecureEmail = Get_CustomerEmail(CustomerID)
sEmail = EncryptDecrypt.DecryptTripleDES(SecureEmail)
AccountName = Get_CustomerAccountName(CustomerID)
End If
To call the next page:
SecureCustomerID = SecureQuerystring.encrypt(CustomerID)
Context.Response.Redirect("nextpage.aspx?cid=" & secureCustomerID)
|
|
|
|
|
guys;
I am working on an none object oriented control written with JQuery that represents a dropdown.
My mission is to make a server control from the JQuery one, also add some properties to ease useing the control.
I am done with the control it self by throwing the HTML and the script to the client on Render() method. But I am facing some problems with properties where i have no object on client side.
what do you suggest me to do?
Help people,so poeple can help you.
|
|
|
|
|
Ali Al Omairi(Abu AlHassan) wrote: where i have no object on client side
Can you clarify this?
No comment
|
|
|
|
|
Sir;
In Microsoft Ajax.Net we create client controls by iheriting from Sys.UI.Control class and we can get it from anywhere in the page by calling $find() method with the cleint id of the element representing the control as a parameter. But in JQuery there are selectors that return JQuery Object holding the elements of the selction and there is no object represeinting the whole control.(where the control may contain more than an element)
Help people,so poeple can help you.
|
|
|
|
|
With Microsoft Ajax all you are getting is a representation of the DOM elements packaged as JavaScript object. JQuery extensions do this also. Everything about the control is in the DOM, either as elements with attributes or JavaScript variables with values.
No comment
|
|
|
|
|
Sir;
you didn't get it. what I wanted was more than a DOM element (e.i. fields, properties, and methods). any way I solved the case by defining a function that represent the constructor of my class, and I added the methods and the properties to the function prototype.
thank you anyway. [EOS]
Help people,so poeple can help you.
|
|
|
|
|
You didn't get it. That is how Microsoft Ajax, JQuery and any other JavaScript framework works. but glad you solved your problem
No comment
|
|
|
|
|
100 , Mark.
Help people,so poeple can help you.
|
|
|
|
|
Server side objects and objects created in the dom with jquery don't mix. there like oil and water. You can create an object server side, and manipulate it in the dom with jquery, but don't expect the value to pass back to the server. Since the server created the object, it expects the same object to post-back to the server, or else the server will detect that someone has altered the object, and trigger an error.
You can create an object in the dom, or the server, and use a web service to pass the value back, relying on something like JSON to format the data, and then send a response back in JSON to the DOM, using JavaScript to decode or parse the response. You can mix JavaScript with JQuery no problem, or just use pure JavaScript to do the work.
So you need to figure out how you want to create the object first. In the dom, you make a panel on the server side , and populate the server side div tag in the dom with your html.
|
|
|
|
|
Hi
I have a VB/ASP.net app which includes a small user database for login data. This location of this database is stored in registry (HKCU) and read by a web page on the client machine (actually server side code) to authenticate the user.
The reason for this is that the Db is installed and managed via a config app installed on the server so the web client doesn't know the Db's location until it reads the registry value set by the config app.
This all works fine on the VS development machine but I cannot read the registry value from the client web app when deployed. I just receive null values.
Same result if using the web page from the server (localhost).
I've mucked about with long enough to guess its probably a permissions thing but I've no idea where to turn to now.
This is the code that is called on the server side app to retrieve the registry value-
Public Function RegistryGet(ByVal regKey As String) As String
Try
Dim regNode As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\XYZ\appX", True)
If regNode Is Nothing Then Call RegistryCreate()
RegistryGet = CStr(regNode.GetValue(regKey, ""))
If RegistryGet.ToString Is Nothing Then
RegistryGet = ""
End If
regNode.Close()
Catch ex As Exception
Return ""
End Try
End Function
This works fine normally but not on the deployed app. Just returns a null yet it can see the registry key and string when stepped through in debug.
BTW, there is definitely a string value to read and all the string/key names match up.
Has anyone any experience with reading server registry from a web form?
regards
Malcom
|
|
|
|
|
WomblingFree wrote: HKCU
The "Current_User" is different! When you debug, the application runs with your user account. When it is deployed, it runs with a different user account (the account for IIS). You could try to store the key in Local_Machine, or in a configuration file.
|
|
|
|
|
Thanks for that.
Figured it was going to be something like this.
HKLM has its own permissions issues with Win 7 and admin access etc which is why I went the HKCU route.
Guess the config file might save me a lot of pain so I'll give that a go.
cheers
|
|
|
|
|
When you test code in the web dev, security is wide open. The web dev is the run f5, in the production environment, can't do that. unless you manipulate the permissions that the code runs in. Your not suppose to be able to alter the windows os with web code. asp.net web apps run in a bubble, in which the root virtual path is your backyard, to do anything you want. Find another way to store the value, like an ini file stored in the AppData.
|
|
|
|
|
Hi All,
For weeks i am strugling, thinking, trying how to proceed further. I have a clean build winforms application. Currently sold to 50 companies with about 700 users. In short i have a separate Datalayer, business layer, framework layer and presentation layer in my application.
Now the question comes that users want to be web-enabled. What is the way to go for me with in mind i do not have a lot of money to spend to buy expensive software tools but i have time and hands .
I want to web-enable my application so i would like to know what is the best way to do this.
How would you proceed?
Are there any usefull frameworks which can work with my business objects?
I think i go for ASP.net any other thoughts?
Many thanks for all thoughts, tips to get me further in this process.
Marcel
|
|
|
|
|
Well, if you have properly separated your code from the presentation then it should be no trouble at all to put a new UI in front of it. If the code is already .NET based then you should stick with ASP.NET.
No comment
|
|
|
|
|
Hi Mark,
It is pretty well seperated. Do you have any suggestions for a asp.net framework i could use make a headstart? I am playing arround with masterpages and can access my business objects for the crud operations.
Anyways..tnx a lot...
|
|
|
|
|
Marcel Vreuls (www.agentbase.nl) wrote: I am playing arround with masterpages and can access my business objects for the crud operations.
That is a good start. What aspects of your existing product do the customers want to see web enabled? Just certain functions or an actual web application that is a replica of the desktop app?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I would love to have a replica of the desktop app. That should not to complicated. I have used, on purpose, only the default .net microsoft controls and have not extented them in order to enhance user experience.
But i am looking for a framework with a nice clean layout where the basic asp.net things are already incorperated like for example breadcrums.
tnx. marcel
|
|
|
|
|
Hi guys,
I have developed a web application which has an option to send email, its all working fine except for the content where i face an issue.
if in an email I send some raw HTML like
Hi, you email is:
test@email.com
The Email client recognizes it as an email and is displayed as a link.
test@email.com
but i dont want it to display as a link whereas it has to be displayed as a plain text
Kindly advise.
Thanks inadvance
Regards,
Tash
|
|
|
|
|
Are you saying you are sending an HTML formatted email and the email address is not encoded, as in not in the form <a mailto:test@email.com>test@email.com</a> but the email client still recognizes it as such? If that is the case then the only option you have is to sent the message as plain text rather than HTML.
No comment
|
|
|
|