i have a div..inside the div i have an image and name..now when i will click on the div the div will have a server side click that means it will have a codebehind function..how to do it?? or how to make my div a button where i don't have to change my div...
my code
<div class="tutorial" style="margin-left:5px;">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
how can i have a server side onclick function of this div???
Not a direct answer. But you can make a button and hide it. Handle the click event of div via Jquery and then on click of div, make the button click.
Here is the answer:
http://forums.asp.net/t/1090438.aspx
You should implement IPostBackEventHandler for your page and register div.
Option 1:
You can make div runat="server":
C#
<div class="tutorial" style="margin-left:5px;"
runat="server" id="tutorial" onClick="tutorial_Click">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
private void tutorial_Click(object sender, System.EventArgs e){
// do stuff
}
VB.NET
<div class="tutorial" style="margin-left:5px;"
runat="server" id="tutorial">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
Private Sub tutorial_Click(object sender, System.EventArgs e) handles tutorial.Click Then
// do stuff
End Sub
Option 2:
OR call __doPostBack() via client (Javascript)
<div class="tutorial" style="margin-left:5px;"
onclick="__doPostBack('tutorial', 'click');">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
private void PageLoad(object sender, System.EventArgs e){
// sttufs
[...]
// my stuff for tutorial click
if (Request["__EVENTTARGET"] == "tutorial" && Request["__EVENTARGUMENT"] == "click"){
TutorialClicked();
}
}
private void TutorialClicked(){
// do stuff
}
Related
I am trying to hide/show text box when radio button is checked/unchecked using ASP.net but i am unable to do it. Can anybody help me out with this? what i am doing due to which i am unable to achieve what i want to.
Thats my asp code
protected void OnCheckChanged(object sender, EventArgs e)
{
lblCC.Visible = false;
txt_cardnum.Visible = false;
}
protected void OnCheckChanged1(object sender, EventArgs e)
{
lblCC.Visible = true;
txt_cardnum.Visible = true;
}
HTML
<asp:RadioButton ID="RadioButtonCC" runat="server" GroupName="PaymentMethod" Checked="true" CssClass="radio-inline" Text="Credit Card" OnCheckedChanged="OnCheckChanged1" />
<asp:RadioButton ID="RadioButtonEP" runat="server" GroupName="PaymentMethod" Text="Easy Paisa" CssClass="radio-inline" OnCheckedChanged ="OnCheckChanged" />
Did you change the AutoPostBack of both the radio controls to True ?
may be this can help you
Hide/Show JTextField
I'm using asp.net button control in my project but this button is unable to bind its Click event, ,I've written button code as
<asp:Button ID="btnProcess" runat="server" Text="Process" class="btn btn-default" OnClick="btnProcess_Click" />
and Code behind as this
protected void btnProcess_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
MultiView1.Visible = true;
GridView.DataSource = Session["Table"];
GridView.DataBind();
}
I'm getting this error when I run that code
'ASP.fileuploadingmodule_aspx' does not contain a definition
for 'btnProcess_Click'
in fact on double clicking this button generates a javascript snippet instead of .cs event handler.
like this :
<script runat="server">
protected void btnProcess_Click(object sender, EventArgs e)
{
}
</script>
Project is made on asp.net 2.0 and visual studio 2012.
Any help will be appreciated.
i have a div..inside the div i have an image and name..now when i will click on the div the div will have a server side click that means it will have a codebehind function..how to do it?? or how to make my div a button where i don't have to change my div...
my code
<div class="tutorial" style="margin-left:5px;">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
how can i have a server side onclick function of this div???
i have used like that but it didn't work for me..don't know why??
<div class="tutorial" style="margin-left:5px;"
runat="server" id="tutorial" onClick="tutorial_Click">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
private void tutorial_Click(object sender, System.EventArgs e){
// do stuff
}
i have tried like that also but it also didn't work for me...
<div class="tutorial" style="margin-left:5px;"
onclick="__doPostBack('tutorial', 'click');">
TUTORIAL<div class="firstico" style="margin-left:70px;margin-top:-17px;">
</div>
</div>
private void PageLoad(object sender, System.EventArgs e){
// sttufs
[...]
// my stuff for tutorial click
if (Request["__EVENTTARGET"] == "tutorial" && Request["__EVENTARGUMENT"] == "click"){
TutorialClicked();
}
}
private void TutorialClicked(){
iframestyle.Attributes["src"] = "userpage.aspx";
}
You will have to handle the click in the div using the Jquery and call server-side methods through JQuery.
Try it.
Source Code :-
<div class="tutorial" style="margin-left:5px;"
runat="server" id="tutorial" onClick="javascript:tutorial_Click('peram1')">click me
</div>
Javascript Code :-
<script type="text/javascript">
function tutorial_Click(parameter)
{
__doPostBack('tutorial', parameter)
}
</script>
Code :-
public void Page_Load(object sender, EventArgs e)
{
string parameter = Request["__EVENTARGUMENT"]; // parameter
// Request["__EVENTTARGET"]; // btnSave
if (parameter == "peram1")
TutorialClicked();
}
private void TutorialClicked(){
//write your code.
}
For more information refer __doPostBack
Lets say you want the page "tutorial.aspx" to be displayed.
Then make your div look like this:
<div class="tutorial" style="margin-left:5px;" onclick="location.href='tutorial.aspx';">
TUTORIAL
</div>
Lets say you have an iframe on your main page; (referring to this part of your code above)
private void TutorialClicked(){ iframestyle.Attributes["src"] = "userpage.aspx"; }
Wrap an anchor around a text like this
User Page
You can try this stuff-
Add a button to your html markup, and set it's style="display: none". so it won't be visible to anyone.
Now add a click event to this button.
When click on div call click event of the button
it may be like below
function tutorial_Click(){
// call here the button click which will do a postback
document.getElementById('<%= btn.ClientID %>').click();
}
4 . Do your code behind stuff at button click event at server side.
Hope this helps.
You can't listen for a click event from the server side. After the server has sent you the required files, the server is no longer involved.
You need a client side listener, jquery is very easy to use.
Index (or whatever html page u got):
<div id="clickme" class="tutorial" style="margin-left:5px;">
<div class="firstico" style="margin-left:70px;margin-top:-17px;">
TUTORIAL
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
$('#clickme').on('click', function () {//can replace '#clickme' for '.tutorial' if you want to be able to click multiple divs
//do stuff
$.ajax({//with ajax you can send a request to the server, and make it do somthing.
url: '/path/to/file',
type: 'post',
data: {variable: 'data'},
success: function(data) {//data is what you echo on from php
//do something on the site
alert(data);//just alert what you echo
}
});
});
</script>
And php (for example) a little but like this:
<?php
function doMe() {
//your function
}
if(isset($_POST['variable'])) {
if($_POST['variable'] === 'data') {
doMe();
}
}
?>
I want to redirect to another page in my website. I have a textbox and a search button in my masterpage.The txt1.text should be the redirection url to be used to navigate to other pages. But i am unable to access the value in txt1.txt in my masterpage.
Please find the code below:-
<asp:TextBox runat="server" ID="txt1" Height="22px" Width="139px" class="searchtextbox"></asp:TextBox>
</div>
<div class="searchicon">
<asp:Button ID="Button5" runat="server" Text="Search" class="searchicon" onclick="Button5_Click"/>
</div>
In my masterpage, i have the code as follows:
protected void Button5_Click(object sender, EventArgs e)
{
{
Response.Redirect("txt1.Text"+".aspx");
}
}
but the value in txt1 is null..
Please help me.
I am trying to have two submit buttons in my form - one accepts meetings; the other declines them. They will both have different behaviours. How can I do is in my C# code?
The functionality I want is essentially
if(isPost) {
if(//accept button pressed(Request.Form[???]))
{
}
else
{
}
}
Here is my HTML :
<button name="accept" type="submit">Accept</button>
<div class="spacer"></div>
<button name="decline" type="submit">Decline</button>
<div class="spacer"></div>
Simple enough, but I cannot find a test for this on the Internet or in any documentation. Does anyone know what I would have for this ?
Give each button element the same name (in this example, 'SubmitButton') but a different value, then do a check for the different values in your server code, ie:
<button type="submit" name="SubmitButton" value="Accept">Accept</button>
<button type="submit" name="SubmitButton" value="Decline">Decline</button>
Then in your server code:
string buttonClicked = Request.Form["SubmitButton"]
if(buttonClicked == "Accept")
{
// Accept code
}
else if(buttonClicked == "Decline")
{
// Decline code
}
Be aware that this won't work on some earlier versions of IE though, and you may have to do a little javascript on the client prior to the post request being made.
As far as I remember, you have a controller action looking like this:
public ActionResult MyAction(string accept, string decline)
{
if (!string.IsNullOrEmpty(accept))
{
//do something
}
else
{
//do something else
}
}
Presuming you are using MVC3 you would do something like
#using (Html.BeginForm("Accept","Meeting"))
{
<input type="submit" value="Accept" />
}
#using (Html.BeginForm("Decline","Meeting"))
{
<input type="submit" value="Decline" />
}
You would then just have your accept and decline code in your Accept and Decline actions of your meeting controller respectively. No need for an if statement at all.
Example controller
public class MeetingController : Controller
{
[HttpPost]
public ActionResult Accept()
{
//Do accept stuff
return View();
}
[HttpPost]
public ActionResult Decline()
{
//Do decline stuff
return View();
}
}
Generally in the codebehind in c# you'd be looking for which button was clicked. You'd have an event handler for each button, and you code would react according to which button was clicked.
this.btnRejectAppointment.Click += new System.EventHandler(this.btnRejectAppointment_Click);
And then your method
private void btnRejectAppointment_Click(object sender, System.EventArgs e)
{
//code to reject appt.
}
And you'd have the SAME set for the other button.
ASP.NET Button control has OnClick event, so add different handler to every your button:
<asp:Button OnClick="MyHandler1" ... />
in code behind:
protected void MyHandler1(object sender, EventArgs args)
{ /* do stuff */ }
One of the possible solutions - use two buttons of type LinkButton but specify slightly different PostBackUrl:
<!-- Accept meeting button -->
<asp:LinkButton ID="acceptMeeting" runat="server"
PostBackUrl="MeetingsManager.aspx?Mode=Accept" />
<!-- Decline meeting button -->
<asp:LinkButton ID="declineMeeting" runat="server"
PostBackUrl="MeetingsManager.aspx?Mode=Decline" />
And in code behind:
public enum Mode
{
Unknown,
Accept,
Decline
}
protected void Page_Load(object sender, EventArgs args)
{
Mode currentMode = Mode.Unknown;
var rawMode = Request.QueryString["Mode"];
if (rawMode != null)
{
currentMode = (Mode)Enum.Parse(
typeof(Mode),
rawMode.ToString())
}
}