Reputation: 4721
I want to open a dialog box
on click of a button
which is inside gridview
but what happens is, whenever I click on button the page is getting refreshed. I tried giving UseSubmitBehavior=false
but still my page is getting postback.
Here is my button
<asp:Button ID="FlAttachParty" runat="server" Width="150px" Height="25px" Text="Add Attachment" OnClick="FlAttachParty_Click" CausesValidation="false" />
Kindly suggest how to achieve this
update
server side code
protected void FlAttachParty_Click(object sender, EventArgs e)
{
if (strMode == "A")
{
if (HidAttachParty.Value == "")
{
ObjPriCon.Open();
OracleCommand objpricmd = new OracleCommand("select xxcus.xxacl_pn_party_info_SEQ.nextval from dual", ObjPriCon);
HidAttachParty.Value = Convert.ToString(objpricmd.ExecuteOracleScalar());
ObjPriCon.Close();
}
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "AttachmentCallParty(" + HidAttachParty.Value + ");", true);
}
else
{
if (HidAttachParty.Value == "")
{
ObjPriCon.Open();
OracleCommand ObjPriCmd = new OracleCommand("select xxcus.xxacl_pn_party_info_SEQ.nextval from dual", ObjPriCon);
HidAttachParty.Value = Convert.ToString(ObjPriCmd.ExecuteOracleScalar());
ObjPriCon.Close();
}
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "AttachmentCallParty(" + HidAttachParty.Value + ");", true);
}
}
Upvotes: 1
Views: 424
Reputation: 48337
Asp:Button
is a server control and for send request to server and get response need page refresh.
The control renders markup as , regardless of whether or not you have a OnClick event tied to it. This means that your form will be submitted to the server upon click, unless you stop it with javascript.
One solution is using Ajax
Call.
Another solution is to use an HTML
button and bind a click
event handler.
<input type="button" id="BtnGo" class="button" value="Go" runat="server" onclick="funShortcuts()" style="height: 21px; width: 40px;" />
The problem is genereting of HidAttachID
.
So you can get here in the following way:
function funShortcuts() {
var str_mkey = "";
var MkeyVal = '<%= Request.QueryString["key"] %>';
if (MkeyVal == "10") {
var r1 = confirm('Do you want to open the attachment form ? ');
if (MkeyVal > 0) {
if (r1 == true) {
str_mkey = "'" + MkeyVal + "'";
}
else {
str_mkey = "'" + MkeyVal + "'";
}
var returnPara = window.showModalDialog("../PreSales/Transactions/FrmCrm_File_Attachment.aspx?Entity='XXACL_PN_PARTY_INFO','XXACL_PN_EXPENSE_INFO','XXACL_PN_VIEW_DATA_INFO'&mkey=" + MkeyVal + "&User_Attach=N&userid=<%=Request.QueryString.Get("userid")%>", null, 'unadorned:yes;resizable:1;dialogWidth:800px;dialogHeight:350px');
document.getElementById('HidCefMkey').value = MkeyVal;
}
else {
alert("Kindly save the form first..!!");
}
}
}
Upvotes: 2