|
dear sir / madam
how to button click event shows random number between 1 to 9
for example: first click event 4
Second click 5
third click 1
.
.
.
thanks
|
|
|
|
|
idea_007 wrote: how to button click event shows random number between 1 to 9
hat is the problem with doing that ? Did you try anything ?
|
|
|
|
|
You should have done google for this.
You can try something like this.
protected void btnRandomGenerator_Click(object sender, EventArgs e)
{
System.Random RandNum = new System.Random();
lblRandomNumber.Text = RandNum.Next(1, 9).ToString();
}
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
hi iam using asp.net2.o with c#
in my application
when user logins iam storing information in ordders table
OrderNo int primary key (auto increment)
email varchar(50)
and redirects to the orders page.and in this page he will retreive the newly primary key generated and stores in session as orders.
but at the same time another user logins then he is also getting the same orderno . how to handle this situation..
can you correct my code which helps me
protected void Button1_Click(object sender, EventArgs e)
{
int x = 0;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox c1 = (CheckBox)row.FindControl("chk");
TextBox qt = (TextBox)row.FindControl("txtQuantity");
TextBox tot1 = (TextBox)row.FindControl("txtTotal");
Label categoryname = (Label)row.FindControl("Label1");
Label ItemKey = (Label)row.FindControl("Label2");
Label ItemKeyNameE = (Label)row.FindControl("Label3");
Label CurrentQTY = (Label)row.FindControl("Label4");
Label SalesPrice = (Label)row.FindControl("Label5");
if (c1.Checked == true)
{
int chempty = 0;
SqlCommand getpk = new SqlCommand("select IDENT_CURRENT('TblOrder')", con);
getpk.CommandTimeout = 0;
con.Open();
x = Convert.ToInt32(getpk.ExecuteScalar());
Session["order"] = x;
con.Close();
SqlCommand cmdtemp = new SqlCommand("Addtemp", con);
cmdtemp.CommandType = CommandType.StoredProcedure;
con.Open();
cmdtemp.Parameters.AddWithValue("@OrderNo", Convert.ToInt32(x));
cmdtemp.Parameters.AddWithValue("@CategoryNameE", categoryname.Text);
cmdtemp.Parameters.AddWithValue("@ItemKey", ItemKey.Text);
cmdtemp.Parameters.AddWithValue("@ItemKeyNameE", ItemKeyNameE.Text);
cmdtemp.Parameters.AddWithValue("@CurrentQTY", CurrentQTY.Text);
cmdtemp.Parameters.AddWithValue("@SalesPrice", SalesPrice.Text);
cmdtemp.Parameters.AddWithValue("@Quantity", qt.Text);
cmdtemp.Parameters.AddWithValue("@total", tot1.Text);
chempty = Convert.ToInt32(cmdtemp.ExecuteNonQuery());
con.Close();
}
}
foreach (GridViewRow ro in GridView1.Rows)
{
CheckBox c2 = (CheckBox)ro.FindControl("chk");
TextBox qt1 = (TextBox)ro.FindControl("txtQuantity");
TextBox tot1 = (TextBox)ro.FindControl("txtTotal");
if (c2.Checked)
{
c2.Checked= false;
qt1.Visible = false;
tot1.Visible = false;
}
}
}
|
|
|
|
|
Of course each user is getting the same order number, you are asking for it. Read the documentation for IDENT_CURRENT.
If you want the id for the inserted record return @SCOPE_IDENTIY() from your insert stored procedure.
Also, mixing inline SQL and stored procedures is asking for maintenance headaches. Pick one, preferably stored procs and us it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
thanks for code project team ....
this logic helps me
|
|
|
|
|
I have some text (shown below) which I want to add to the page. This text contains server side script which I would also like to add dynamically. Is this a possibility?
So far I have attempted to add the text as controls using Page.ParseControl. This successfully adds the controls (textbox and button) to the page but the button events are not working (postback so far looks good).
After researching this further, several possibilities came into play. The first was CodeCompiler and the second was Dynamic Language Extensibility Model (DLEM). I have not read too much into DLEM but the article I read talked mostly about IronPython so this approach may not work in my scenario. In any case, both of these seem like overkill.
I figured before I continue with my research, I would ask for suggestions from the community.
Here are my questions:
1) Are the above possibilities a reasonable approach?
2) Is there something else I should be looking into?
3) Is it even possible to add server side scripts to a page dynamically?
Thanks in advance.
protected override void OnInit(EventArgs e)
{
string formText = @"
<script runat=""server"">
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
((Button)sender).Text = TextBox1.Text;
}
</script>
<asp:TextBox ID=""TextBox1"" runat=""server""></asp:TextBox>
<asp:Button ID=""btn1"" runat=""server"" onclick=""Button1_Click""></asp:Button>
";
Control dControl = Page.ParseControl(formText);
Page.Form.Controls.Add(dControl);
base.OnInit(e);
}
|
|
|
|
|
You can't add the server side script to the page from you code-behind. Think about it, what would be the point? You are already in the code-behind, so just add the controls. You are trying to make it much more complicated than it is.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I want to be able to be able to add scripts AFTER my application has already been compiled. Like VSA. In this example I have added it to my codebehind but the real-life example will not have the string in the code behind.
modified on Sunday, June 20, 2010 10:49 AM
|
|
|
|
|
Why would you? Without a great deal more complexity you can't. There are other ways to accomplish your task I'm sure, why don't you tell us what you want to accomplish and what you think you are gaining by trying to insert code in the manner.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I am trying to create a 'Content Management System' type of app. I want to add 'pages' dynamically with server controls markup and attach them to events.
So bascially, I want to be able to write an entire asp.net page w/ server side scripts in text and execute it at run-time.
What I have been able to accomplish so far is creating the control. However, hooking on to the events is whats causing me problems.
|
|
|
|
|
You do understand that SERVER side scripts are processed on the SERVER? Injecting them in the page on the server is not going to accomplsih anything.
Take a look at other CMS applications such as SharePoint and you will fined they use templates and page level parsers to inject dynamic controls into the output stream.
To add a control and event handler to the page you do something like this.
protected void OnInit(...)
{
Button myBtn = new Button();
myBtn.Text = "Some text";
myBtn.Click += new OnClick;
Page.Controls.Add(myBtn);
}
protected void OnClick(object sender, EventArgs e)
{
...
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I understand the server side scripts are executed in the server but I figured that there has to be a point during the life cyle where the markup, including the scripts, are parsed and compiled into dlls. This is where I wanted to inject my text. Seems like I may have to find another solution.
Thanks for your input.
|
|
|
|
|
I think what you're trying to do is something along these lines (excuse my VB code - you'll have to trasnlate it yourself if you want)
First, add a placeholder control on the form where you want to add the new control, and also a literal (just so we can test things_ -eg:
<asp:PlaceHolder runat="server" ID="phHere"></asp:PlaceHolder>
<p><asp:Literal runat="server" ID="litClick"></asp:Literal></p>
Then in your code behind, add this:
Private Sub btnNewButton_Click(ByVal Sender As Object, ByVal e As EventArgs)
litClick.Text = "Clicked!"
End Sub
and in the Page_Load event, add this:
Dim btn As New Button
btn.ID = "btnNewButton"
btn.Text = "My new button"
AddHandler btn.Click, AddressOf btnNewButton_Click
phHere.Controls.Add(btn)
|
|
|
|
|
Thanks for your response. Thats not exactly what I am trying to do. I want to be able to add dynamic code after my app has been build... just lke VSA.
|
|
|
|
|
I’m developing a .NET/C# application software for an instrument which has a built-in PC (Core 2 CPU/2.66GZ/4GB RAM) and will have access to the Internet from behind the facility IT firewall. To support remote device maintenance via Intetnet using browser, I want to run a web site locally IIS hosted on the instrument PC. Apparently, this site is for authorized user only (could be anywhere on the Inernet). I know security is the major problem to deal with in this scenario. To reduce the surface of attach, can I lock down the allowable IP range to just one IP address where the service user is? This one IP address will be made configurable. Is this a viable approach to secure the web site with the least cost?
Just googled that .htaccess file can be created in webroot to block IP ranges. Will this still allow scripts to access the site
Sorry, .htaccess is available on Apache server only. What's equivalent on IIS?
modified on Saturday, June 19, 2010 10:19 PM
|
|
|
|
|
From IIS Manager; (This sequence is 2003 Server, but dare say others are similiar)
1) Right Click the Web Site and choose Properties
2) Select the Directory Security Tab
3) Click Edit in the IP Address and Domanin Name restrictions panel
4) Grant/Deny relevant domains/ip as required.
|
|
|
|
|
Is it possible to do it in code? e.g. after receiving an allowable IP address, place it somewhere in a config file?
|
|
|
|
|
Yeah, it's possible to do in code using WMI, you can read here[^] how to do it. You should change binding for the application.
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
|
I was recently going through one site and the url of that site was www.abc.com/default.asp
But that site was quite techy - so it can't be of that old asp days. Shouldn't it be .aspx in the end ? Or am i missing something.
Thank You
Andyyy
|
|
|
|
|
If they are hosting the site on their own server (or at least a server to which they have full admin access) then they could map asp files to .net - this is a simple setting in IIS. (Though one has to wonder why anyone would want to do this.)
But otherwise, there are still a lot of sites out there still in clasic asp. "If it ain't broke, don't fix it" is a good maxim in any field. Sometimes the work, time and money involved in upgrading a site is more than it's worth.
|
|
|
|
|
Hi All! I am trying to process several requests to a website, performing posts of data and processing page results. I'm finding it seems very inefficient, and actually it seems to take longer to process the request than compared to typing in manually.
Looking at the code below it appears there isn't a way to simplify or move initialization of objects to another method, rather than performing it each request is made (the requests are being made to the same website).
Here is my code below.
Thanks for all your help!
private string ProcessFormPOST(string strURL, string strFormData)
{
try
{
byte[] buffer = Encoding.UTF8.GetBytes(strFormData);
string proxy = null;
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new System.Net.WebProxy(proxy, true);
req.CookieContainer = new System.Net.CookieContainer();
System.IO.Stream reqst = req.GetRequestStream();
reqst.Write(buffer, 0, buffer.Length);
reqst.Close();
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.Stream resst = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resst);
return sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
}
|
|
|
|
|
Hi you experts, I want to write a Googlemap than UserControl so that the
Control may often be involved in a Page.
Lattitude, Longtiude should be enter. Creates should be a Linkbutton activated
a ModalPopup in which the inside is GoogleMap
What do you think? Do you have other ideas?
|
|
|
|