using classic asp code inside asp.net? - asp.net

I have a application that running both classic asp and asp net. inside the classic asp page, I have a combo box and depends on the selection of the combo box I need to do something inside my asp.net page. For instance, if inside my classic asp page, I have a combo box and inside the combo box; book is selected than when I enter a price for book as a zero inside my asp.net page I supposed to get an alert. Is there any way to do that?
asp.net code
if (Convert.ToDecimal(Values["myBookPrice"]) == 0)
{
//You cannot use 0 price for books!
}

Let say that you have some input control on any page, html, asp what ever, with some parametre that you wish to pass to an asp.net page
if the input control have a name attribute like
<form method="post" action="thenewpage.aspx">
<input name="nameOfInput" type="text" id="idofinput" />
<input type="submit" name="btnGo" value="Create Box" id="btnGo" />
</form>
and you have a button that make post back to an asp.net page, then you get that parametre on asp.net side using the Request.Form and the name of the input control as:
Request.Form["nameOfInput"]
If you make a call the page with url parameter, you need to use some kind of javascript to dynamically create the URL string for the call.
The issue that you have here, is that the asp.net page will hit the validation of the page security because is not going to find the page validation informations he needed to secure the page.

Related

can I run multiple server side forms in asp .net

In my project I want to run 2 forms in one webpage which is master page one is for contact us and one is for signup user. but multiple server side forms are not allowed. is there any solution for fix it?
You can use postback ability of Asp.net Webforms.
You should create one button for singup and another one for contact. You can catch event in server side and you do what want to do.
You can create regular client side forms created using HTML in the master page, and use the Request.Form to read the posted data. For this to work, all the input elements must have a name, and you can read them using Request.Form["ElementName"].
Take into account that forms cannot be nested.
So, your master page needs to llok like this
...
<body>
<form id="form1" runat="server">
</form>
<form id="contact" action="Contact.aspx" method="post">
<input type="text" name="Message"/>
<input type="submit" value="Contact us!"/>
</form>
</body>
The first <form> is the regular ASP.NET server side form, which supports server side components
The second <form> is a custom HTML form. It doesn't have the runat="server" attribute, and it's outside the server side <form>.
The second form action points to a .aspx page. In its page load event you can use the Request.Form["Name"] to acces the name of the contact form. Note that you also need to include a submit button to send the data to the server, and a method="post" to specify the method to send the page.
This is resorting to "basic" HTML controls, so there is no View State, and the posted values will be lost if they're not reset in the server. I.e. if the form is posted, and there's an error, the previously posted values will be lost when rendering the page again.
If you want to make it more sophisticated you can use Javascript and, optionally AJAX. But that's a more complex solution. See this for an example.
ASP.NET Forms only supports one form. You could use an iFrame and render your second page (second form) inside of the iFrame.
Here is an interesting post about placing some page content after the tag. This may be helpful to you.
http://forums.asp.net/t/1611822.aspx?Dynamically+adding+content+to+page+outside+of+the+aspnet+form+from+within+a+UC

Text Box Values got lost in ASP.NET page load Event

currently i was working in asp.net web application .
In asp page i was assign values to all controls on page load event using the Query string value.
On Compiling with break point i was able to see the values in the text box and other controls.But after completing the Page load event all my assigned values for the text boxes *got lost.*
Help me to solve this issue
in ASP page
<input type="hidden" id="hidtext" runat="server" value="">
in JScript
<script>
document.getElementById("hidtext").value = document.getElementById("textbox1")
.value;
</script>
after post back
textbox1.text=hidtext.value;

How can I create Simple aspx webpage which will send me parameters in the link

I am trying to do something from scratch in asp
I would like to get something like below. From basic hard coded values.
http://localhost:2478/Default.aspx?phone=905123456&order=123456
After that I want to use this parameter in my variables for SQLquery
I am new to asp.net and vb , I'm learning. Can you please explain me in details? Any helps will be appreciate.
Can you please provide any basic code from where I can start
Based on your latest comments:
<form method="get" action="default.aspx">
<input type="text" name="phone" />
<input type="text" name="order" />
<input type="submit" value="submit" />
</form>
Key points:
method=get (fields are in url instead of body)
note that the form above doesn't have runat=server (more below) - it's a plain HTML Form on plain HTML page
in the context of ASP.Net Web forms, you may run into issues particularly if you are using Master Pages (you can't nest forms, and a Master page is a container for your entire page).
ASP.Net forms do POSTbacks - re: method=post
You can use/add plain forms in an ASP.Net page as long as you don't nest them (outside of the server side ASP.Net form).
If you have no choice (e.g. Master Page), you'll have to construct the Querystring manually after a POSTback, then Response.Redirect to some other target (adding the querystring manually).
there are other non-ASP.Net-y ways of doing it - e.g. javascript, but that a different story

userControl repeated with Form tag disappearing

I have a Contact userControl that have "save contact" as submit button and fields inside form tag we repeat this userControl with Code 20 times in one page
My problem is the Form Tag in the first userControl is hiding somehow --- i checked the userControl with developer Tool IE9 , firebug Firefox7 and the Form is not appearing in the first userControl and its appearing with the rest 19 Controls
I tried to View Source and take html copy in new html file in VS -- i found form is exist
i dont know if iam clear enough but please advice if you need more info
If you're running a form tag at the server, inside a user control, and then displaying this user control more than once on the page, then you will have multiple form tags running at server on one page, which is not allowed by ASP.NET
Take the form tag outside of the user control like:
<form runat="server">
<uc:Contact />
<uc:Contact />
<uc:Contact />
</form>

aspx: a form is always forwarded to the same page

on the page products.aspx i created a form:
<form id="send_info_form" method="post" action="send_email.aspx">
<input type="text" name="the_name />
<input type="submit" />
</form>
when i click on submit it's forwarded to the same page (products.aspx) and not to the page i set in action attribute of the form.
It looks like you have a misunderstanding about how ASP.NET's logic works- ASP.NET has a much different paradigm than PHP or ASP does.
It seems like you're taking more of an ASP classic or PHP approach of directly handling the landing pages of forms and POST values, which you no longer have to do. You shouldn't need a separate page to handle the logic of the form submission either; this is all handled by event handlers in the submitting page's codebehind.
Instead of handling input elements directly, you should use ASP.NET's server controls to handle all the inputs for you.
What you should be doing is:
In the Products.aspx page:
E-mail Address: <asp:TextBox runat="server" ID="txtEmail" />
<asp:Button runat="server" ID="btnSubmit" OnClick="btnSubmit_Click" Text="Submit" />
Note that there's no form tag required (besides the one already provided to you when you first make the ASPX page.
Since you're working with an object-oriented language with a business objects representing all of your HTML elements with ASP.NET, you don't have to handle reading from the POST values of the form directly.
In the codebehind for Products.aspx (I'm assuming C#, so Products.aspx.cs), add a method for btnSubmit_Click:
protected void btnSubmit_Click(object sender, EventArgs e) {
string sendEmailTo = txtEmail.Text;
// insert mail sending logic here
}
In ASP.NET, the tag will by default always post itself to the same page. This allows you to handle any events in the codebehind in the ASPX page. It's not clear from your question what exactly you're trying to do. I can think of three possible scenarios:
1) You want to post back to the same page, and toggle visibility of UI elements (other panels, etc.) based on the result of the processing, or redirect the user to a second destination page once processing is complete. This is the most common scenario and the approach I recommend be taken, because it keeps all the logic regarding the processing of the form in one place.
2) You can specify a PostBackUrl to specify another (ASP.NET) page for button controls and whatnot. From there you can do the processing from elements on the first page on the second page using the PreviousPage property. See http://msdn.microsoft.com/en-us/library/ms178139.aspx for more information.
3) If you have a separate page you wish to post to that you don't control that's not ASP.NET-based (i.e., another site's form, or a PHP/ASP3.0 site you run), things get significantly more difficult. ASP.NET puts everything in one giant elements. Since tags cannot reliably be embedded within each other in HTML, you will either have to do a silent POST manually from your codebehind, or use Javascript to quietly submit an ajax request upon submission.

Resources