I am using a button inside a form, and this from is inside another form. When button is inside the second form its calling directly page load event but not button click event. If I take the button outside the second form nothing will work neither its call page load method nor button click event.
<form id="form1" runat="server">
<form class="ak-form" method="post" action="#">
<ul class="agileits ">
<li class="agileits">
<input required="" id="txtCustMailId" runat="server" class="text-box-dark agileits " type="text" value="Enter Your Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Enter Your Email';}" name="email" /></li>
<li class="agileits">
<input required="" id="txtCustPass" runat="server" class="text-box-dark agileits " type="password" value="Your Password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Password';}" name="password" /></li>
</ul>
<div class="ak-btn-cont ak-btn-booking-cont login-btn">
<asp:Button runat="server" class="btn btn-primary agileits button2" CssClass="btn btn-info btnWidth100 btnFont" ID="btnCustLogin" ValidationGroup="CustLogin" Text="Login" OnClick="btnCustLogin_Click" />
<asp:Button runat="server" class="btn btn-primary agileits button2" CssClass="btn btn-info btnWidth100 btnFont" ID="Button2" Text="Forgot Password" OnClick="btnCustLogin_Click1" />
</div>
</form>
</form>
Consolidate the two forms into one form.
<form id="form1" class="ak-form" method="post" action="#" runat="server">
</form>
If you can't do this because #form1 is wrapping the entire page and in implementation the .ak-form is deeper in the documentation then try adding the runat="server" attribute to the second form element.
Related
i have to values values one form to another using asp.net i can pass to another only regno and name only another values cannot pass i got the error missing directive what i tried so far i attached below
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label>Reg No</label>
<asp:TextBox ID="regno" runat="server" class="form-control" required></asp:TextBox>
</div>
<div class="form-group">
<label>Name</label>
<asp:TextBox ID="name" runat="server" class="form-control" required></asp:TextBox>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" id="phone" name="phone" class="form-control" required />
</div>
<div class="form-group">
<label>Gender</label>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="FeMale" />
</div>
<div class="form-group">
<label>Interest</label>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Cricket" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="Football" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Cinima" />
</div>
<div class="form-group">
<asp:Button ID="Button1" runat="server" Text="Submit" class="btn btn-success" OnClick="Button1_Click" />
</div>
</div>
Button Event
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("form2.aspx?regno=" +
this.regno.Text + "&name=" +
this.name.Text + "&phone=" +
this.phone.Text ); this line i got error missing directive
}
Second form
Label1.Text = Request.QueryString["regno"];
Label2.Text = Request.QueryString["name"];
Label3.Text = Request.QueryString["phone"];
phone seems to be ordinary input and not TextBox (note the input tag and lowercase id). Also, you are requesting a txtphone while id=phone.
Be aware, string data should be Url encoded before sending it through querystring.
Edit: replace
<input type="text" id="phone" name="phone" class="form-control" required />
with
<asp:TextBox ID="phone" runat="server" class="form-control" required></asp:TextBox>
Edit: for checkboxes, use something like
var interests = new List<string>();
if (chkCheckBox1.Checked)
interests.Add(chkCheckBox1.Text);
if (chkCheckBox2.Checked)
interests.Add(chkCheckBox2.Text);
if (chkCheckBox3.Checked)
interests.Add(chkCheckBox3.Text);
var interestsString = string.Join(",", interests);
var sex = RadioButton1.Checked ? RadioButton1.Text : RadioButton1.Text;
Response.Redirect("form2.aspx" +
"?regno=" + this.regno.Text +
"&name=" + this.name.Text +
"&phone=" + this.phone.Text +
"&sex=" + HttpUtility.UrlEncode(sex) +
"&interest=" + HttpUtility.UrlEncode(interestsString) +
// if needed, decode with HttpUtility.UrlDecode(Request.QueryString["interest"]:
// var interests = HttpUtility.UrlEncode(interestsString);
In my asp.net webform project I'm trying to add asp:panel for search field. I need to use defaultbutton attribute.
<div class="input-group">
<asp:Panel ID="pnlSearch" runat="server" DefaultButton="btnSearch">
<input class="form-control" placeholder="Search" autocomplete="off" runat="server" onkeypress="searchclick('btnSearch',event);" id="txtSearch" />
<div class="input-group-btn">
<button class="btn btn-default" id="btnSearch" itemid="btnSeach" onserverclick="btnSearch_ServerClick" runat="server" type="submit"><i
class="glyphicon glyphicon-search"></i></button>
</div>
</asp:Panel>
</div>
When I try to do this I took error like.
error screen
If I just remove defaultbutton attribute the error is gone.
I have an online banking login that I'm trying to take from an old client site and put on their new site. If I copy the form and paste it into my new site, it just reloads the page when submitted. I've tried to change it to an asp.net form using the appropriate and other applicable tags with the same result.
If I take the form and put it in a simple index.html file, it submits and takes me to the correct external site.
I was unable to set the ID & values with the asp.net form and that may be one of the issues.
Any help is appreciated.
Here is the HTML form version that works in .html page that needs to work in .aspx page:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="my value">
<input type="hidden" name="iid" value="another value">
<div class="field-container">
<label for="aid" id="aid-label">Access ID</label>
<input name="aid" id="aid" type="text" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');" />
</div>
<div class="field-container">
<label for="passcode" id="passcode-label">Passcode</label>
<input name="passcode" id="passcode" type="password" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');"/>
</div>
<div class="form-row">
<input type="submit" name="Submit" value="Go" class="button">
</div>
</form>
Here is my asp.net form version that I tried:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="some value">
<input type="hidden" name="iid" value="another value">
<asp:TextBox runat="server" ID="sssid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox runat="server" ID="iid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<div class="form-group">
<asp:Label runat="server" id="lblAccessID"></asp:Label>
<asp:TextBox runat="server" ID="txtAccessID" CssClass="form-control"> </asp:TextBox>
</div>
<div class="form-group">
<asp:Label runat="server" id="lblPassCode"></asp:Label>
<asp:TextBox runat="server" ID="txtPasscode" CssClass="form-control" TextMode="Password"></asp:TextBox>
</div>
<button type="submit" class="btn btn-blue">GO
<img src="/Content/img/icon-sm-arrow.png" alt="" />
</button>
</form>
My asp.net form code behind:
protected void Page_Load(object sender, EventArgs e)
{
txtAccessID.Attributes.Add("placeholder", "Access ID");
txtPasscode.Attributes.Add("placeholder", "Passcode");
}
I had to use the following to post this correctly:
<asp:LinkButton runat="server" ID="btnSubmit" CssClass="btn btn-blue" PostBackUrl="urlhere" Text='GO <img src="/Content/img/icon-sm-arrow.png" alt="" />' />
set PostBackUrl property of Button control => https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl(v=vs.110).aspx
the reason webforms always posting it 2 itself may be due to their __doPostBack script.
I am trying to click on an ASP:Button with an onclick function. Every time I do that the HTML5 Required stops the click from occurring. I even tried to include an ASP:UpdatePanel but that does not work neither.
<form id="form1" name="theform" class="form-horizontal" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="fb_login" runat="server">
<asp:button CssClass="btn-facebook" ID="FacebookButton" Text="Login with Facebook" OnClick="FacebookButton_Click" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="container">
<div class="form-group">
<label for="FirstName">First Name</label>
<div>
<input type="text" tabindex="1" class="form-control" id="FirstName" required title="Enter First Name" runat="server" placeholder="First Name">
</div>
</div>
<div class="form-group">
<label for="LastName">Last Name</label>
<div>
<input type="text" tabindex="2" class="form-control" id="LastName" required title="Enter Last Name" runat="server" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary">Submit Information</button>
</div>
</div>
</div>
</form>
Remove the UpdatePanel and set UseSubmitBehavior="false" on FacebookButton:
<asp:button UseSubmitBehavior="false" CssClass="btn-facebook" ID="FacebookButton" Text="Login with Facebook" OnClick="FacebookButton_Click" runat="server" />
ok, i have this:
<div class="radio-toolbar">
<input type="checkbox" id="check1" name="checks" value="1">
<label for="check1">1</label>
<input type="checkbox" id="check2" name="checks" value="2">
<label for="check2">2</label>
<input type="checkbox" id="check3" name="checks" value="3">
<label for="check3">3</label>
</div>
and i'm looking for a way to set the "onclick" attribute of those labels with ASP.NET VB Codebehind, making the labels looks like:
<div class="radio-toolbar">
<input type="checkbox" id="check1" name="checks" value="1">
<label for="check1" onclick="some javascript">1</label>
<input type="checkbox" id="check2" name="checks" value="2">
<label for="check2" onclick="some javascript">2</label>
<input type="checkbox" id="check3" name="checks" value="3">
<label for="check3" onclick="some javascript">3</label>
</div>
so, is that possible?
Use a asp:Label.
<asp:Label ID="lblChk1" runat="server" AssociatedControlID="check1" Text="1">
</asp:Label>
Then in your code behind:
lblChk1.Attributes.Add("onclick","some javascript");
Edit: You could simply use asp:CheckBox and use its Text Property. Clicking the text would then fire the onclick event of your CheckBox.
Set the ID attribute and add runat=server for your labels. Then you can access the labels from your code-behind:
<div class="radio-toolbar">
<input type="checkbox" id="check1" name="checks" value="1">
<label ID="label1" runat="server" for="check1">1</label>
<input type="checkbox" id="check2" name="checks" value="2">
<label ID="label2" runat="server" for="check2">2</label>
<input type="checkbox" id="check3" name="checks" value="3">
<label ID="label2" runat="server" for="check3">3</label>
</div>
Instead of a html label i would use the ASP.NET Label control with AssociatedControlID attribute which is rendered as label for.
<asp:Label ID="Label1"
AssociatedControlID="check1"
onclick="somejavascript"
runat="server"
Text="1"></asp:Label>
You can also add the javascript from codebehind:
Label1.Attributes.Add("onclick","somejavascript");
From MSDN:
...
When the AssociatedControlID property is set, the Label control
renders as an HTML label element, with the for attribute set to the ID
property of the associated control. You can set other attributes of
the label element using the Label properties. For example, you can use
the Text and AccessKey properties to provide the caption and hot key
for an associated control.
`