Submit form (without runat=server) from aspx page - asp.net

as we all know there is only one form possible on aspx page. How can I add html form to aspx page from code begind and submit data of this created form?
Here is form example:
<form name="payment" method="post" action="https://sci.interkassa.com/" accept-charset="UTF-8">
<input type="hidden" name="ik_co_id" value="51237daa8f2a2d8413000000" />
<input type="hidden" name="ik_pm_no" value="ID_4233" />
<input type="hidden" name="ik_am" value="1.44" />
<input type="hidden" name="ik_desc" value="Payment Description" />
<input type="submit" value="Pay">
</form>
I have and idea to build string using ClientScriptManager first and than attach this form to div using jQuery. Something like that. Is there some bettre ideas?
I'm going to use something like that, but I don't like this solution:
Dim sname As [String] = "Interkassa"
Dim stype As Type = Me.[GetType]()
Dim cs As ClientScriptManager = Page.ClientScript
If Not cs.IsStartupScriptRegistered(stype, sname) Then
Dim sb As New StringBuilder()
sb.Append("<script type=text/javascript>")
sb.Append("$(document).ready(function () { var s = ""<form name='payment' method='post' action='https://sci.interkassa.com/' accept-charset='UTF-8'><input type='submit' value='Оплата через Интеркассу'></form>"";")
sb.Append("html = $.parseHTML(s);$('#interkassa').append(html);});")
sb.Append("</script>")
cs.RegisterStartupScript(stype, sname, sb.ToString())
End If

You don't need to add the HTML using code behind. That's a bad practice because it provides poor separation between logic and markup. Instead, create a button on your page where it fires a server side event, then have your server side event handle the logic.
<asp:Panel runat="server" ID="MyPaymentPanel">
<asp:Button runat="server" ID="SubmitPaymentBtn" Text="Pay" OnClick="SubmitPaymentBtn_Click" />
</asp:Panel>
Then in your code behind...
protected void SubmitPaymentBtn_Click(object sender, EventArgs e)
{
//Retrieve values for ik_co_id, ik_pm_no etc from your database
//post the form if sending to a site you don't control, or update your database if you control sci.interkassa.com
}

Try like this
<button id="ClearButton" class="Button2" onclick="javascript:temp();return false;">CLEAR</button>
<script type=text/javascript>
Function temp
{
// your code
}
</script>

Related

How to send text to content page as query string from Master Page

I have a search textbox that I tried wrapping in a form element:
<form id="searchForm" method="GET" action="Search.aspx">
<input name="term" type="text" id="searchTerm" class="nav-search" size="30" />
<input type="submit" value="submit" style="display:none;"/>
</form>
I can't get it to redirect to the content page (Search.aspx) with the query string (term) from the Master Page.
I tried wrapping it in an ASP:Panel and using the DefaultButton Property but that wouldn't call the Click event in code behind.
I'm perplexed as I've searched for a solution for hours and this seems like a such common task. Thanks.
Change your code to this
<input name="term" type="text" id="searchTerm" runat="server" class="nav-search" size="30" />
<asp:Button ID="searchsubmit" OnClick="searchsubmit_Click" runat="server" Text="Search" />
in Site.Master.cs add something like this
protected void searchsubmit_Click(object sender, EventArgs e)
{
Response.Redirect("~/search.apsx?content=" + searchTerm.text);
}
This will allow to search with button click, if you want to hide it, add also panel around first code, saying that this is a button to automatically press when enter is pressed Something like this:
<asp:Panel ID="UserPanel" runat="server" DefaultButton="searchsubmit">

HTML textbox value always returns an empty string at asp.net button click event

I have a simple stopwatch application which updates HTML textbox values using a javascript.
<form name="clock">
<input type="text" size="12" name="stwa" value="00 : 00 : 00" style="texalign:center"/>
<input type="text" size="12" name="stwb" style="text-align:center" /><br />
<input type="button" name="theButton" onClick="stopwatch(this.value);" value="Start" />
<input type="button" value="Reset" onClick="resetIt();reset();" />
</form>
I also have an asp.net button control which should submit value in 'stwb' at the button click. Although stwb textbox gets updated with the javascript correctly, it always returns an empty string at button click.
<form id="form1" runat="server">
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click"/>
</form>
Button click event for the method.
protected void Button2_Click(object sender, EventArgs e)
{
String strValue = Page.Request.Form["stwb"].ToString();
Response.Write(strValue);
}
Appreciate any help in this regard.
You have two forms; HTML forms submit independently.
Thus, when your server form submits, the data for your "clock" form is not passed as part of the request.
The easiest solution is probably to place your clock inside the form with the runat=server attribute.

When a radio button is checked in one asp page,the result has to be displayed in another asp page..How to do that..pls explain?

Radio button in one aspx page ,
should display result in another aspx page
where was 2012 olympics held??
<form name="form1" action="resultpage.aspx" onclick="submit">
<input type="radio" name="VanPersie" id="a" value="paris" />paris<br />
<input type="radio" name="VanPersie" id="b" value="london" />london<br />
<input type="radio" name="VanPersie" id="c" value="rome" />rome<br />
<input type="submit" value="Submit"/>.
Above code displays my first home page and it has to be redirected to another aspx page....so when..london is checked by the user,it has to display the correct answer and i.e. London ..how to design the result page...
Presuming you have a button that fire a event in your page, you can set the PostbackUrl attribute to the page you want and where you can retrive the value
<asp:Button ID="btn" runat="server" Text="Send to other page" postbackurl="yourPage.aspx" />
Post ASP.NET Web Pages to a Different Page
1 You can use this code
var result = radioButtonList.SelectedValue;
Response.Redirect("AnotherPage?id=" + result);
In page you can get with
`QueryString["id"]`;
2 You can also use
yourButton.PostBackUrl = "AnotherPage.aspx?qid=" + radioButtonList.SelectedValue;
First set the method attribute to the form to POST
<form name="form1" action="resultpage.aspx" onclick="submit" method="POST">
Then, if you subit this form from an ASP page, in the resultpage.aspx you can get the radio value by:
//C#
protected void Page_Load(object sender, EventArgs e)
{
Request.Form["VanPersie"];
}
'VB
Protected Sub Page_Load(sender As Object, e As EventArgs)
Request.Form("VanPersie")
End Sub

Passing a value from Page_Load to Form with POST

I'm really new to ASP and have a project where I need to capture the login of the person logged into Sharepoint. I have created the following code and am able to get the login. I am having trouble pass the parameter to a form. What is the best way to do this: I know the 2nd part the POST is wrong, I don't know what to do here. Thanks for your help. Scott
<script language="C#" runat="server">void Page_Load(Object sender, EventArgs e)
{
string userName = "NA";
userName = HttpContext.Current.User.Identity.Name;
string userWithoutDomain = userName.Substring(userName.IndexOf('\\') + 1);
myuserid.Text = userWithoutDomain;
}
</script>
<html>
<body>
<form method="POST" action="http://srs.xxx.edu:9001/signon/authenticate.asp" id="myuserid" name="myuserid">
<input type="hidden" name="COOKIEPATH" value="/SRS/">
<input style="width:70px;font-size:8pt;" size="8" name="myuserid" >
<input style="width:70px;font-size:8pt;" size="8" name="myuserid" >
<input class="button" type="submit" value=" Log On " style="display:none;">
</form>
<form id="form1" runat="server">
<asp:label id="myuserid" runat="server" />
</form>
</body>
</html>
You can pass values from the codebehind to html page using for example hidden values, see here.
Usually though values are placed into form elements in the codebehind directly. If the element has the "runat=server" attribute then you can access the element in the Page_Load method using c# and just set the text value directly.
myuserid.Text =

Password-Box not showing any content

I have a small websolution that needs the user to input a password. I have two input boxes
<input type="password" runat="server" id="m_txtPassword1"/>
If I set some chars to the Value-property of the control like this:
m_txtPassword1.Value="someChars";
The password box is rendered empty. No bullets are shown. If I look into the rendered html-source, also no value-tag has been rendered. If I change the type to
<input type="text" runat="server" id="m_txtPassword1"/>
the chars are shown. Is this by design? How can I disable this feature?
Please note, I don't want to put a real password into the value-property, I only want to show the user that there is already a password set, and this is IMO done best with some 8 bullets in the input-control. But for this, I need the possibility to set the value-property of the control.
Update
For all, having the same problem: I have tried to declare <asp:textbox id="m_txtPassword1" runat="server" TextMode="Password" /> with the same result. Also m_txtPassword1.Attributes["value"]="someChars" has not helped.
It seems that this is realy not possible.
As a workaround, I declared the password-boxes as plain html without the runat="server" and have set the value-property in markup (via two properties from the code-behind). Not nice but I really want to show the user that he has already entered a password.
Another workaround would be to set the value through javascript on load.
This is by default. You cannot set a password.
I make this works,
<html>
<head>
<script type="text/javascript">
function alertValue()
{
alert(document.getElementById("password1").value);
}
function setpassword()
{
password1.value="someChars";
}
</script>
</head>
<body>
<form>
<input type="password" id="password1" value="" />
<input type="button" id="button1" onclick="alertValue()" value="Show default value" />
<input type="button" id="button2" onclick="setpassword()" value="Set value" />
</form>
</body>
</html>
Try this:
http://jsbin.com/ocexo5
It is by design, for security reasons - so that the password is not in the
HTML in plain text.
Now, you could write out javascript to set the value property of the textbox
on the client, of course this would still mean that you have the password in
plain text in the HTML.
Here is example of the page:
Markup:
<script type="text/javascript">
function setPwd()
{
var Pwd = "<%=Pwd %>";
var txtText = document.getElementById("MainContent_txtText");
txtText.value = Pwd;
}
</script>
<input type="password" id="txtText" runat="server"/>
And code-behind:
public partial class _Default : System.Web.UI.Page
{
public string Pwd;
protected void Page_Load(object sender, EventArgs e)
{
Pwd = "password";
ClientScript.RegisterStartupScript( this.GetType(),"somescript","setPwd();",true);
}
}
Textbox11.Attributes.Add("Value",whatever_your_password_is)

Resources