Button click only fires when IP in the URL not computer name - c#

I have an asp.net webform. When I browse to the URL using the computer name ie: http://somecomputer/mypage.aspx the button click events do NOT fire. Other events do like selected index changed or text changed but the button click does not.
If I navigate to the page by IP, ie: http://192.168.100.1/mypage.aspx, then the button click fires and everything works as expected. Why is this and how can I fix it?
here is the button click html:
<div class="li_div">
<asp:Button ID="btnInventoryRpt" runat="server"
Text="Load Report" OnClick="btnInventoryRpt_Click" CausesValidation="false" UseSubmitBehavior="False" />
</div>
Here is the code behind:
protected void btnInventoryRpt_Click(object sender, EventArgs e)
{
load_inventory_report();
}

Related

asp.net search button just refreshing page

Im trying to create a search button on my website on my homepage which is an aspx page but when I click search all it does is refresh the page instead of preforming the query, any help would be appreciated
heres the code for my index.aspx and the code for my index.aspx.cs page
<asp:TextBox ID="searchtitle" runat="server"></asp:TextBox>
<asp:Button ID="searchitems" runat="server" Text="Search" />
protected void searchitems_Click(object sender, EventArgs e)
{
String stext = searchtitle.Text;
Response.Redirect("search.aspx?searchquery=" + stext);
}
The button is not working because you didnt call the event on the button
<asp:Button ID="searchitems" runat="server" OnClick="searchitems_Click" Text="Search" />
add OnClick attribute with name of the event you want to call and in the given code the event you want to call is searchitems_Click.
definitely when you will click the searchitems page will reload because function for that click is defined on server side.. what you have to do is on the pageload look for the QueryString and get the value of ["searchquery"] then manipulate it as you want..
if you want to not refresh the page use Ajax then...

Click event not being called for HTML submit button

I need to add button in user control. When the button is clicked url should be captured and stored in a session. When I click the button, server click event is not being called. I am in confusion why it is not being called. Did I made anything wrong here? Please suggest.
I have the following code:
ascx:
<input type="submit" id="QuickViewbutton" value="Click to add this page to Quick View"
runat="server" onserverclick="addQuickView" clientidmode="Static"/>
ascx.cs:
In page load:
QuickViewbutton.ServerClick += new System.EventHandler(this.addQuickView);
In protected void addQuickView(Object sender, EventArgs e) function I have written the code for fetching url:
string strUrl = HttpContext.Current.Request.Url.AbsoluteUri;
Session["QuickViewUrl"] = strUrl;

how to include a User Control in a Web Forms Page from code behind?

im trying to make a user control to popup when a button is clicked! now i dont want to hide the user control and then show it when the button is clicked,
im NOT trying to do this:
test1.aspx
<uc1:PopUp ID="PopUp1" runat="server" Visible="false" />
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
test1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
if(PopUp1.Visible==false)
PopUp1.Visible = true;
else
PopUp1.Visible = false;
}
i want the page loads without it and if the button is clicked it fires! is it possible?
btw, im open to any other suggestion other than using user control
thank you in advance

Fire html button using .cs page

i need to fire html buttom after the end of my asp.net c# code
<asp:Button ID="Button3" runat="server"
Text="Button" onclick="Button3_Click" />
<input id="Button2" type="button" value="button" data-type="error" class="growl-type2" runat="server" />
and cs code is
protected void Button3_Click(object sender, EventArgs e)
{
----
i need to fire button2( automatically) in this position
}
Button clicks are just handled events. To fire a button click you simply need to raise the correct event.
You'll need something like: Button2_Click(sender, e)
Alternatively, you can inject some Javascript into the page, which reacts directly to the click of button3 or is caused by the click of button3 and causes the click of button2 through something like: document.getElementById('Button2').click()

User Control Buttons Not Firing

I have a user control that allows the user to add/edit a worker. When the user clicks the 'Add Worker' button the user control appears in a DevExpress Popup. All of the following button are in an update panel to prevent Postbacks.
When I edit a user (pencil) everything works fine. To edit a user I enter a last name, click search (magnifying glass) and then click edit (pencil). It's only when I load the page and click add the save/cancel buttons do not work.
I add the control in asp.net
<dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server" SupportsDisabledAttribute="True">
<uc:WorkerAddEdit ID="wae" runat="server" OnOnWAECancelEvent="wae_OnWAECancelEvent" OnOnWAESaveEvent="wae_OnWAESaveEvent" />
</dx:PopupControlContentControl>
Here is the C# code behind the edit (the one that works correctly. The pencil)
protected void btnEditWorker_Click(object sender, EventArgs e)
{
SetupSessions();
wae.WorkerEdit = loadedWorker;
pucAddEditWorker.HeaderText = "Edit Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the C# code behind for the add (the round + that doesn't work)
protected void btnAddWorker_Click(object sender, EventArgs e)
{
wae.WorkerEdit = null;
pucAddEditWorker.HeaderText = "Add Worker";
pucAddEditWorker.ShowOnPageLoad = true;
}
Here is the asp.net section of the save and cancel button. This shows both onClick calls
<td><dx:ASPxButton ID="btnSave" runat="server" Text="Save" Theme="MetropolisBlue"
Width="50px" Height="20px" style="float:right;" onclick="btnSave_Click" /></td>
<td><dx:ASPxButton ID="btnCancel" runat="server" Text="Cancel"
Theme="MetropolisBlue" Width="50px" Height="20px" style="float:right;"
onclick="btnCancel_Click" /></td>
Here is the events in the code behind
protected void btnCancel_Click(object sender, EventArgs e)
{
//Do Work Here
}
protected void btnSave_Click(object sender, EventArgs e)
{
// Do Work Here
}
If I put a break point on either the save or cancel click event nothing ever happens. I've been googling for a while now with no luck.
Thanks in advance.
In Design mode of the form, have you tried clicking the control once, and check it on Properties (Events) window? Maybe the Click event does not have any method selected.
Select the btnSave_Click method in the Click label.
I figured out what the problem was. I am using a textbox from DevExpress. Further up in my code I had the textbox as follows:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue" >
<MaskSettings Mask="(999) 000-0000" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
Because I had the 0's in the mask it was trying to validate whatever was in the text box. Because I turned off the validation settings (ValidationSettings Display="None") I never saw the error but it was still validating. I made a change to this:
<dx:ASPxTextBox ID="txtPhoneNumber" runat="server" Width="100px" Theme="MetropolisBlue">
<MaskSettings Mask="(999) 999-9999" IncludeLiterals="None" />
<ValidationSettings Display="None">
</ValidationSettings>
</dx:ASPxTextBox>
and everything worked fine. I just started using DevExpress and it shows! Thanks to everyone for the help!

Categories

Resources