Unable to make value fields editable after clicking on a link button - javascript

I've created a link button and made a event handler for it. But still unable to make the values editable.
This is the link button:
<FooterTemplate>
<asp:LinkButton ID="lbEdit" runat="server" OnClick="lbEdit_Click">Edit</asp:LinkButton>
</FooterTemplate>
Here is the code behind:
protected void lbEdit_Click(object sender, EventArgs e)
{
dvEAEdit.DefaultMode = DetailsViewMode.Edit;
}
Any help is appreciated!

Related

Why IE cannot close tab on "Cancel" button click c#

I have this cancel button:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Cancel" />
I want click that button it will close the current window, so in codebehind:
protected void Button1_Click(object sender, EventArgs e)
{
string jScript = "<script>window.close();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "keyClientBlock", jScript);
// Response.Write("<script>parent.close_window();</script>");
}
But I do not see that window tab close in my IE browser. Is there anything can be corrected here?
Why are you doing this server side when you can just attach to the buttons click event in js/jQuery?
This probably wont work due to a browser security setting unless the window itself was spawned via the window.open() method, so you'll want to use a workaround if this is absolutely necessary.
<script type="text/javascript">
$('#button').click(function(e){
e.preventDefault();
window.open('','_self').close();
});
</script>
<button id="button" value="close" />
function CloseWindow() {
window.open('','_self').close();
}
Code Behind
protected void Button1_Click(object sender, EventArgs e)
{
string jScript = "<script>CloseWindow();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "keyClientBlock", jScript);
}
I would also suggest to create a function in javascript and then just call it with your code, and if your not going to do anything in the .cs side us DGibs answer.

Chrome bug asp.net updatepanel posts twice

This is my markup:
<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtEmail" AutoPostBack="true" OnTextChanged="txtEmail_TextChanged" />
<asp:Panel runat="server" Visible="false" ID="pnl">
<asp:TextBox runat="server" ID="txtUname" AutoPostBack="true" OnTextChanged="txtUname_TextChanged" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
and this is the code behind:
and these are the event handlers in the code behind:
protected void txtEmail_TextChanged(object sender, EventArgs e)
{
pnl.Visible = true;
updPnl.Update();
txtUname.Focus();
}
protected void txtUname_TextChanged(object sender, EventArgs e)
{
}
If I press enter on txtEmail textbox it works fine in all browsers and the focus comes to txtUName textbox except Chrome. On debugging I found that is happening because Chrome makes Ajax request twice. Is there anyway to fix this Chrome bug?
Note that it works fine in Chrome too if I use Tab instead of enter. However, I need to fix this Chrome bug of Enter too.
you may enter key trigger a post to the form,
you should prevent the submit action on enter (so enter key and tab key would have the same behavior)
you can do it with JavaScript (onkeydown) for instance.
however, I think update panel here is an overkill,
why not to use only JavaScript on the client side?
$("#txtEmail").change(function() {
var email = $(this).val();
// now you can do whatever you want with the value.
});

ASP.Net session not updated in javascript

when my button is clicked I fire the javascript to get the session..
But value of session not updated...
alert('<%= Session["file"]%>');
It won't be up to date if its changed after the page is rendered.
You might want to look at page methods (an ajax system) or another ajax approach.
Any inline code once rendered to the page will not change, which is a normal behavior.
use a Hidden field instead.
mark-up:
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
code-behind:
protected void Button1_Click(object sender, EventArgs e)
{
Session["file"] = "Data Here";
HiddenField1.Value = Session["file"].ToString();
}
javascript:
alert(document.getElementById('<%= HiddenField1.ClientID %>').value);

click() Event in javascript with a PARAM?

I'm using the event click() to call a method in Code Behind, like this:
HTML
<asp:button bordercolor="White" id="btnAddGS" onclick="AddGSBandeira" runat="server">
JAVASCRIPT
$("#ctl00_ContentPlaceHolder1_btnAddGS").click();
C#
public void AddGSBandeira(object sender, EventArgs e)
{
}
Its work normally, but I need to pass a param in the javascript call, like this:
$("#ctl00_ContentPlaceHolder1_btnAddGS").click("param");
But I do not know how this works ...can anybody help?
The best thing to do is create a hidden control and populate it's value with JavasScript on the click event. Your code behind will be able to access that value on your postback (AJAX or otherwise).
Markup
<asp:HiddenField ID="myHiddenField" runat="server" />
<asp:button bordercolor="White" id="btnAddGS"
onclick="AddGSBandeira"
onclientclick="SetHiddenValue()" runat="server">
JavaScript
function SetHiddenValue()
{
document.getElementById("<%=myHiddenField.ClientID%>").value = "[Your value here]";
}
C#
public void AddGSBandeira(object sender, EventArgs e){}
{
var jsVal = myHiddenField.Value;
}
You can do this with trigger.
http://api.jquery.com/trigger/
$("#ctl00_ContentPlaceHolder1_btnAddGS").trigger("click",["param"]);
I believe the 2nd parameter to trigger should be an array of arguments to pass to the function.

Why can't I hit the event handler in the code behind doing a modal popup postback

I am basically trying to do what this article says.
link text I am able to postback, but my handler is not getting hit. Any ideas?
Code Behind
protected void Page_Init(object sender, EventArgs e)
{
WireEvents();
}
private void WireEvents()
{
btnAuthOk.Click += new EventHandler(btnAuthOk_Click);
btnAuthOk.OnClientClick = string.Format("fnClickOK('{0}','{1}')", btnAuthOk.ClientID, string.Empty);
}
private void btnAuthOk_Click(object sender, EventArgs e)
{
DoSomeCodeHere();
}
Javascript & HTML
function fnClickOK(sender, e) {
__doPostBack(sender, e);
}
<p>To allow this payment to be processed, enter an authorized User ID and Password</p>
<p>User ID: <asp:TextBox runat="server" ID="txtAuthUser" CssClass="underlinedTextBox" Columns="8" />
<asp:Literal runat="server" ID="spauth" Text=" " />
Password : <asp:TextBox runat="server" ID="txtAuthPass" TextMode="Password" CssClass="underlinedTextBox" Columns="10" />
</p>
<asp:Button runat="server" ID="btnAuthOk" Text="Submit" CssClass="popupAuthButton" UseSubmitBehavior="false" />
</asp:Panel>
<cc1:ModalPopupExtender ID="authPE" runat="server" PopupControlID="popupAuth"
OkControlID="btnAuthOk" TargetControlID="hdnPopupTarget" BackgroundCssClass="modalBackground" />
Thanks for any help here...
Cheers,
~ck
PS Stack is mucking my html a bit as I don't know how to properly post HTML. Is someone can edit and fix, I appreciate it. :)
I found that setting UseSubmitBehavior="false" actually allows me to hit my code.
If you just want your OK button to do a postback, simply remove the OkControlID attribute from your ModalPopupExtender markup.
I know, I know - that sounds ridiculous. But when you specify OK and Cancel button ID's to the MPE, it actually disables them from posting back on the client side.

Categories